Harald Welte | be3c38c | 2023-11-23 22:08:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * GSM RLP (Radio Link Protocol) as used in CSD (3GPP TS 44.022) |
| 3 | * |
| 4 | * Copyright (C) 2022-2023 Harald Welte <laforge@osmocom.org> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | |
| 21 | #pragma once |
| 22 | #include <stdint.h> |
| 23 | #include <stdbool.h> |
| 24 | #include <osmocom/core/utils.h> |
| 25 | |
| 26 | /*! \defgroup rlp GSM RLP (Radio Link Protocol) as used in CSD (3GPP TS 24.022) |
| 27 | * @{ |
| 28 | * \file rlp.h */ |
| 29 | |
| 30 | /*! RLP frame type as per 3GPP TS 24.022 Section 5.2.1 */ |
| 31 | enum osmo_rlp_ftype { |
| 32 | OSMO_RLP_FT_U, |
| 33 | OSMO_RLP_FT_S, |
| 34 | OSMO_RLP_FT_IS, |
| 35 | }; |
| 36 | extern const struct value_string osmo_rlp_ftype_vals[]; |
| 37 | |
| 38 | /*! RLP U-Frame Type as per 3GPP TS 24.022 Section 5.2.1 */ |
| 39 | enum osmo_rlp_u_ftype { |
| 40 | OSMO_RLP_U_FT_SABM = 0x07, |
| 41 | OSMO_RLP_U_FT_UA = 0x0c, |
| 42 | OSMO_RLP_U_FT_DISC = 0x08, |
| 43 | OSMO_RLP_U_FT_DM = 0x03, |
| 44 | OSMO_RLP_U_FT_NULL = 0x0f, |
| 45 | OSMO_RLP_U_FT_UI = 0x00, |
| 46 | OSMO_RLP_U_FT_XID = 0x17, |
| 47 | OSMO_RLP_U_FT_TEST = 0x1c, |
| 48 | OSMO_RLP_U_FT_REMAP = 0x11, |
| 49 | }; |
| 50 | extern const struct value_string osmo_rlp_ftype_u_vals[]; |
| 51 | |
| 52 | /*! RLP S-Frame type as per 3GPP TS 24.022 Section 5.2.1 */ |
| 53 | enum osmo_rlp_s_ftype { |
| 54 | OSMO_RLP_S_FT_RR = 0, |
| 55 | OSMO_RLP_S_FT_REJ = 2, |
| 56 | OSMO_RLP_S_FT_RNR = 1, |
| 57 | OSMO_RLP_S_FT_SREJ = 3, |
| 58 | }; |
| 59 | extern const struct value_string osmo_rlp_ftype_s_vals[]; |
| 60 | |
| 61 | /*! Data structure representing one decoded RLP frame */ |
| 62 | struct osmo_rlp_frame_decoded { |
| 63 | uint8_t version; |
| 64 | enum osmo_rlp_ftype ftype; |
| 65 | enum osmo_rlp_u_ftype u_ftype; |
| 66 | enum osmo_rlp_s_ftype s_ftype; |
| 67 | bool c_r; |
| 68 | bool p_f; |
| 69 | uint8_t s_bits; |
| 70 | uint16_t n_s; |
| 71 | uint16_t n_r; |
| 72 | uint32_t fcs; |
| 73 | uint8_t info[536/8]; |
| 74 | uint16_t info_len; |
| 75 | }; |
| 76 | |
| 77 | int osmo_rlp_decode(struct osmo_rlp_frame_decoded *out, uint8_t version, const uint8_t *data, size_t data_len); |
| 78 | int osmo_rlp_encode(uint8_t *out, size_t out_size, const struct osmo_rlp_frame_decoded *in); |
| 79 | uint32_t osmo_rlp_fcs_compute(const uint8_t *in, size_t in_len); |
| 80 | |
| 81 | /*! @} */ |