Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 1 | /* GPRS SNDCP XID field encoding/decoding as per 3GPP TS 44.065 */ |
| 2 | |
| 3 | /* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * Author: Philipp Maier |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 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 Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <osmocom/core/linuxlist.h> |
| 26 | |
Philipp | db142dc | 2016-12-22 14:15:20 +0100 | [diff] [blame] | 27 | #define DEFAULT_SNDCP_VERSION 0 /* See 3GPP TS 44.065, clause 8 */ |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 28 | #define MAX_ENTITIES 32 /* 3GPP TS 44.065 reserves 5 bit |
| 29 | * for compression enitity number */ |
| 30 | |
| 31 | #define MAX_COMP 16 /* Maximum number of possible pcomp/dcomp values */ |
| 32 | #define MAX_NSAPI 11 /* Maximum number usable NSAPIs */ |
| 33 | #define MAX_ROHC 16 /* Maximum number of ROHC compression profiles */ |
| 34 | |
Stefan Sperling | c572154 | 2018-11-07 16:33:39 +0100 | [diff] [blame^] | 35 | /* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */ |
| 36 | enum gprs_sndcp_hdr_comp_algo { |
| 37 | RFC_1144, /* TCP/IP header compression, see also 6.5.2 */ |
| 38 | RFC_2507, /* TCP/UDP/IP header compression, see also: 6.5.3 */ |
| 39 | ROHC /* Robust Header Compression, see also 6.5.4 */ |
| 40 | }; |
| 41 | |
| 42 | /* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */ |
| 43 | enum gprs_sndcp_data_comp_algo { |
| 44 | V42BIS, /* V.42bis data compression, see also 6.6.2 */ |
| 45 | V44 /* V44 data compression, see also: 6.6.3 */ |
| 46 | }; |
| 47 | |
| 48 | union gprs_sndcp_comp_algo { |
| 49 | enum gprs_sndcp_hdr_comp_algo pcomp; |
| 50 | enum gprs_sndcp_data_comp_algo dcomp; |
| 51 | }; |
| 52 | |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 53 | /* According to: 3GPP TS 44.065, 6.5.1.1 Format of the protocol control |
| 54 | * information compression field (Figure 7) and 3GPP TS 44.065, |
| 55 | * 6.6.1.1 Format of the data compression field (Figure 9) */ |
| 56 | struct gprs_sndcp_comp_field { |
| 57 | struct llist_head list; |
| 58 | |
| 59 | /* Propose bit (P), see also: 6.5.1.1.2 and 6.6.1.1.2 */ |
| 60 | unsigned int p; |
| 61 | |
| 62 | /* Entity number, see also: 6.5.1.1.3 and 6.6.1.1.3 */ |
| 63 | unsigned int entity; |
| 64 | |
| 65 | /* Algorithm identifier, see also: 6.5.1.1.4 and 6.6.1.1.4 */ |
Stefan Sperling | c572154 | 2018-11-07 16:33:39 +0100 | [diff] [blame^] | 66 | union gprs_sndcp_comp_algo algo; |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 67 | |
| 68 | /* Number of contained PCOMP / DCOMP values */ |
| 69 | uint8_t comp_len; |
| 70 | |
| 71 | /* PCOMP / DCOMP values, see also: 6.5.1.1.5 and 6.6.1.1.5 */ |
| 72 | uint8_t comp[MAX_COMP]; |
| 73 | |
| 74 | /* Note: Only one of the following struct pointers may, |
| 75 | be used. Unused pointers must be set to NULL! */ |
| 76 | struct gprs_sndcp_pcomp_rfc1144_params *rfc1144_params; |
| 77 | struct gprs_sndcp_pcomp_rfc2507_params *rfc2507_params; |
| 78 | struct gprs_sndcp_pcomp_rohc_params *rohc_params; |
| 79 | struct gprs_sndcp_dcomp_v42bis_params *v42bis_params; |
| 80 | struct gprs_sndcp_dcomp_v44_params *v44_params; |
| 81 | }; |
| 82 | |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 83 | /* According to: 3GPP TS 44.065, 8 SNDCP XID parameters */ |
| 84 | enum gprs_sndcp_xid_param_types { |
| 85 | SNDCP_XID_VERSION_NUMBER, |
| 86 | SNDCP_XID_DATA_COMPRESSION, /* See also: subclause 6.6.1 */ |
| 87 | SNDCP_XID_PROTOCOL_COMPRESSION, /* See also: subclause 6.5.1 */ |
Stefan Sperling | c572154 | 2018-11-07 16:33:39 +0100 | [diff] [blame^] | 88 | SNDCP_XID_INVALID_COMPRESSION /* Not part of the spec; this means we found an invalid value */ |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | /* According to: 3GPP TS 44.065, 6.5.2.1 Parameters (Table 5) */ |
| 92 | struct gprs_sndcp_pcomp_rfc1144_params { |
| 93 | uint8_t nsapi_len; /* Number of applicable NSAPIs |
| 94 | * (default 0) */ |
| 95 | uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */ |
| 96 | int s01; /* (default 15) */ |
| 97 | }; |
| 98 | |
| 99 | /* According to: 3GPP TS 44.065, 6.5.2.2 Assignment of PCOMP values */ |
| 100 | enum gprs_sndcp_pcomp_rfc1144_pcomp { |
| 101 | RFC1144_PCOMP1, /* Uncompressed TCP */ |
| 102 | RFC1144_PCOMP2, /* Compressed TCP */ |
| 103 | RFC1144_PCOMP_NUM /* Number of pcomp values */ |
| 104 | }; |
| 105 | |
| 106 | /* According to: 3GPP TS 44.065, 6.5.3.1 Parameters (Table 6) */ |
| 107 | struct gprs_sndcp_pcomp_rfc2507_params { |
| 108 | uint8_t nsapi_len; /* Number of applicable NSAPIs |
| 109 | * (default 0) */ |
| 110 | uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */ |
| 111 | int f_max_period; /* (default 256) */ |
| 112 | int f_max_time; /* (default 5) */ |
| 113 | int max_header; /* (default 168) */ |
| 114 | int tcp_space; /* (default 15) */ |
| 115 | int non_tcp_space; /* (default 15) */ |
| 116 | }; |
| 117 | |
| 118 | /* According to: 3GPP TS 44.065, 6.5.3.2 Assignment of PCOMP values for RFC2507 */ |
| 119 | enum gprs_sndcp_pcomp_rfc2507_pcomp { |
| 120 | RFC2507_PCOMP1, /* Full Header */ |
| 121 | RFC2507_PCOMP2, /* Compressed TCP */ |
| 122 | RFC2507_PCOMP3, /* Compressed TCP non delta */ |
| 123 | RFC2507_PCOMP4, /* Compressed non TCP */ |
| 124 | RFC2507_PCOMP5, /* Context state */ |
| 125 | RFC2507_PCOMP_NUM /* Number of pcomp values */ |
| 126 | }; |
| 127 | |
| 128 | /* According to: 3GPP TS 44.065, 6.5.4.1 Parameter (Table 10) */ |
| 129 | struct gprs_sndcp_pcomp_rohc_params { |
| 130 | uint8_t nsapi_len; /* Number of applicable NSAPIs |
| 131 | * (default 0) */ |
| 132 | uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */ |
| 133 | int max_cid; /* (default 15) */ |
| 134 | int max_header; /* (default 168) */ |
| 135 | uint8_t profile_len; /* (default 1) */ |
| 136 | uint16_t profile[MAX_ROHC]; /* (default 0, ROHC uncompressed) */ |
| 137 | }; |
| 138 | |
| 139 | /* According to: 3GPP TS 44.065, 6.5.4.2 Assignment of PCOMP values for ROHC */ |
| 140 | enum gprs_sndcp_pcomp_rohc_pcomp { |
| 141 | ROHC_PCOMP1, /* ROHC small CIDs */ |
| 142 | ROHC_PCOMP2, /* ROHC large CIDs */ |
| 143 | ROHC_PCOMP_NUM /* Number of pcomp values */ |
| 144 | }; |
| 145 | |
| 146 | /* ROHC compression profiles, see also: |
| 147 | http://www.iana.org/assignments/rohc-pro-ids/rohc-pro-ids.xhtml */ |
| 148 | enum gprs_sndcp_xid_rohc_profiles { |
| 149 | ROHC_UNCOMPRESSED = 0x0000, /* ROHC uncompressed [RFC5795] */ |
| 150 | ROHC_RTP = 0x0001, /* ROHC RTP [RFC3095] */ |
| 151 | ROHCV2_RTP = 0x0101, /* ROHCv2 RTP [RFC5225] */ |
| 152 | ROHC_UDP = 0x0002, /* ROHC UDP [RFC3095] */ |
| 153 | ROHCv2_UDP = 0x0102, /* ROHCv2 UDP [RFC5225] */ |
| 154 | ROHC_ESP = 0x0003, /* ROHC ESP [RFC3095] */ |
| 155 | ROHCV2_ESP = 0x0103, /* ROHCv2 ESP [RFC5225] */ |
| 156 | ROHC_IP = 0x0004, /* ROHC IP [RFC3843] */ |
| 157 | ROHCV2_IP = 0x0104, /* ROHCv2 IP [RFC5225] */ |
| 158 | ROHC_LLA = 0x0005, /* ROHC LLA [RFC4362] */ |
| 159 | ROHC_LLA_WITH_R_MODE = 0x0105, /* ROHC LLA with R-mode [RFC3408] */ |
| 160 | ROHC_TCP = 0x0006, /* ROHC TCP [RFC6846] */ |
| 161 | ROHC_RTP_UDP_LITE = 0x0007, /* ROHC RTP/UDP-Lite [RFC4019] */ |
| 162 | ROHCV2_RTP_UDP_LITE = 0x0107, /* ROHCv2 RTP/UDP-Lite [RFC5225] */ |
| 163 | ROHC_UDP_LITE = 0x0008, /* ROHC UDP-Lite [RFC4019] */ |
| 164 | ROHCV2_UDP_LITE = 0x0108, /* ROHCv2 UDP-Lite [RFC5225] */ |
| 165 | }; |
| 166 | |
| 167 | /* According to: 3GPP TS 44.065, 6.6.2.1 Parameters (Table 7a) */ |
| 168 | struct gprs_sndcp_dcomp_v42bis_params { |
| 169 | uint8_t nsapi_len; /* Number of applicable NSAPIs |
| 170 | * (default 0) */ |
| 171 | uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */ |
| 172 | int p0; /* (default 3) */ |
| 173 | int p1; /* (default 2048) */ |
| 174 | int p2; /* (default 20) */ |
| 175 | |
| 176 | }; |
| 177 | |
| 178 | /* According to: 3GPP TS 44.065, 6.6.2.2 Assignment of DCOMP values */ |
| 179 | enum gprs_sndcp_dcomp_v42bis_dcomp { |
| 180 | V42BIS_DCOMP1, /* V.42bis enabled */ |
| 181 | V42BIS_DCOMP_NUM /* Number of dcomp values */ |
| 182 | }; |
| 183 | |
| 184 | /* According to: 3GPP TS 44.065, 6.6.3.1 Parameters (Table 7c) */ |
| 185 | struct gprs_sndcp_dcomp_v44_params { |
| 186 | uint8_t nsapi_len; /* Number of applicable NSAPIs |
| 187 | * (default 0) */ |
| 188 | uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */ |
| 189 | int c0; /* (default 10000000) */ |
| 190 | int p0; /* (default 3) */ |
| 191 | int p1t; /* Refer to subclause 6.6.3.1.4 */ |
| 192 | int p1r; /* Refer to subclause 6.6.3.1.5 */ |
| 193 | int p3t; /* (default 3 x p1t) */ |
| 194 | int p3r; /* (default 3 x p1r) */ |
| 195 | }; |
| 196 | |
| 197 | /* According to: 3GPP TS 44.065, 6.6.3.2 Assignment of DCOMP values */ |
| 198 | enum gprs_sndcp_dcomp_v44_dcomp { |
| 199 | V44_DCOMP1, /* Packet method compressed */ |
| 200 | V44_DCOMP2, /* Multi packet method compressed */ |
| 201 | V44_DCOMP_NUM /* Number of dcomp values */ |
| 202 | }; |
| 203 | |
| 204 | /* Transform a list with compression fields into an SNDCP-XID message (dst) */ |
| 205 | int gprs_sndcp_compile_xid(uint8_t *dst, unsigned int dst_maxlen, |
Philipp | db142dc | 2016-12-22 14:15:20 +0100 | [diff] [blame] | 206 | const struct llist_head *comp_fields, int version); |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 207 | |
| 208 | /* Transform an SNDCP-XID message (src) into a list of SNDCP-XID fields */ |
Philipp | db142dc | 2016-12-22 14:15:20 +0100 | [diff] [blame] | 209 | struct llist_head *gprs_sndcp_parse_xid(int *version, |
| 210 | const void *ctx, |
| 211 | const uint8_t *src, |
| 212 | unsigned int src_len, |
| 213 | const struct llist_head |
| 214 | *comp_fields_req); |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 215 | |
| 216 | /* Find out to which compression class the specified comp-field belongs |
| 217 | * (header compression or data compression?) */ |
Stefan Sperling | c572154 | 2018-11-07 16:33:39 +0100 | [diff] [blame^] | 218 | enum gprs_sndcp_xid_param_types gprs_sndcp_get_compression_class( |
Philipp | 22611be | 2016-08-10 12:08:03 +0200 | [diff] [blame] | 219 | const struct gprs_sndcp_comp_field *comp_field); |
| 220 | |
| 221 | /* Dump a list with SNDCP-XID fields (Debug) */ |
| 222 | void gprs_sndcp_dump_comp_fields(const struct llist_head *comp_fields, |
| 223 | unsigned int logl); |
| 224 | |