blob: e64bc5237566ce9e123441268bb8ac25ae18bb67 [file] [log] [blame]
Philipp22611be2016-08-10 12:08:03 +02001/* 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
Philippdb142dc2016-12-22 14:15:20 +010027#define DEFAULT_SNDCP_VERSION 0 /* See 3GPP TS 44.065, clause 8 */
Philipp22611be2016-08-10 12:08:03 +020028#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
35/* According to: 3GPP TS 44.065, 6.5.1.1 Format of the protocol control
36 * information compression field (Figure 7) and 3GPP TS 44.065,
37 * 6.6.1.1 Format of the data compression field (Figure 9) */
38struct gprs_sndcp_comp_field {
39 struct llist_head list;
40
41 /* Propose bit (P), see also: 6.5.1.1.2 and 6.6.1.1.2 */
42 unsigned int p;
43
44 /* Entity number, see also: 6.5.1.1.3 and 6.6.1.1.3 */
45 unsigned int entity;
46
47 /* Algorithm identifier, see also: 6.5.1.1.4 and 6.6.1.1.4 */
48 int algo;
49
50 /* Number of contained PCOMP / DCOMP values */
51 uint8_t comp_len;
52
53 /* PCOMP / DCOMP values, see also: 6.5.1.1.5 and 6.6.1.1.5 */
54 uint8_t comp[MAX_COMP];
55
56 /* Note: Only one of the following struct pointers may,
57 be used. Unused pointers must be set to NULL! */
58 struct gprs_sndcp_pcomp_rfc1144_params *rfc1144_params;
59 struct gprs_sndcp_pcomp_rfc2507_params *rfc2507_params;
60 struct gprs_sndcp_pcomp_rohc_params *rohc_params;
61 struct gprs_sndcp_dcomp_v42bis_params *v42bis_params;
62 struct gprs_sndcp_dcomp_v44_params *v44_params;
63};
64
65/* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */
66enum gprs_sndcp_hdr_comp_algo {
67 RFC_1144, /* TCP/IP header compression, see also 6.5.2 */
68 RFC_2507, /* TCP/UDP/IP header compression, see also: 6.5.3 */
69 ROHC /* Robust Header Compression, see also 6.5.4 */
70};
71
72/* According to: 3GPP TS 44.065, 6.5.1.1.4 Algorithm identifier */
73enum gprs_sndcp_data_comp_algo {
74 V42BIS, /* V.42bis data compression, see also 6.6.2 */
75 V44 /* V44 data compression, see also: 6.6.3 */
76};
77
78/* According to: 3GPP TS 44.065, 8 SNDCP XID parameters */
79enum gprs_sndcp_xid_param_types {
80 SNDCP_XID_VERSION_NUMBER,
81 SNDCP_XID_DATA_COMPRESSION, /* See also: subclause 6.6.1 */
82 SNDCP_XID_PROTOCOL_COMPRESSION, /* See also: subclause 6.5.1 */
83};
84
85/* According to: 3GPP TS 44.065, 6.5.2.1 Parameters (Table 5) */
86struct gprs_sndcp_pcomp_rfc1144_params {
87 uint8_t nsapi_len; /* Number of applicable NSAPIs
88 * (default 0) */
89 uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */
90 int s01; /* (default 15) */
91};
92
93/* According to: 3GPP TS 44.065, 6.5.2.2 Assignment of PCOMP values */
94enum gprs_sndcp_pcomp_rfc1144_pcomp {
95 RFC1144_PCOMP1, /* Uncompressed TCP */
96 RFC1144_PCOMP2, /* Compressed TCP */
97 RFC1144_PCOMP_NUM /* Number of pcomp values */
98};
99
100/* According to: 3GPP TS 44.065, 6.5.3.1 Parameters (Table 6) */
101struct gprs_sndcp_pcomp_rfc2507_params {
102 uint8_t nsapi_len; /* Number of applicable NSAPIs
103 * (default 0) */
104 uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */
105 int f_max_period; /* (default 256) */
106 int f_max_time; /* (default 5) */
107 int max_header; /* (default 168) */
108 int tcp_space; /* (default 15) */
109 int non_tcp_space; /* (default 15) */
110};
111
112/* According to: 3GPP TS 44.065, 6.5.3.2 Assignment of PCOMP values for RFC2507 */
113enum gprs_sndcp_pcomp_rfc2507_pcomp {
114 RFC2507_PCOMP1, /* Full Header */
115 RFC2507_PCOMP2, /* Compressed TCP */
116 RFC2507_PCOMP3, /* Compressed TCP non delta */
117 RFC2507_PCOMP4, /* Compressed non TCP */
118 RFC2507_PCOMP5, /* Context state */
119 RFC2507_PCOMP_NUM /* Number of pcomp values */
120};
121
122/* According to: 3GPP TS 44.065, 6.5.4.1 Parameter (Table 10) */
123struct gprs_sndcp_pcomp_rohc_params {
124 uint8_t nsapi_len; /* Number of applicable NSAPIs
125 * (default 0) */
126 uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */
127 int max_cid; /* (default 15) */
128 int max_header; /* (default 168) */
129 uint8_t profile_len; /* (default 1) */
130 uint16_t profile[MAX_ROHC]; /* (default 0, ROHC uncompressed) */
131};
132
133/* According to: 3GPP TS 44.065, 6.5.4.2 Assignment of PCOMP values for ROHC */
134enum gprs_sndcp_pcomp_rohc_pcomp {
135 ROHC_PCOMP1, /* ROHC small CIDs */
136 ROHC_PCOMP2, /* ROHC large CIDs */
137 ROHC_PCOMP_NUM /* Number of pcomp values */
138};
139
140/* ROHC compression profiles, see also:
141 http://www.iana.org/assignments/rohc-pro-ids/rohc-pro-ids.xhtml */
142enum gprs_sndcp_xid_rohc_profiles {
143 ROHC_UNCOMPRESSED = 0x0000, /* ROHC uncompressed [RFC5795] */
144 ROHC_RTP = 0x0001, /* ROHC RTP [RFC3095] */
145 ROHCV2_RTP = 0x0101, /* ROHCv2 RTP [RFC5225] */
146 ROHC_UDP = 0x0002, /* ROHC UDP [RFC3095] */
147 ROHCv2_UDP = 0x0102, /* ROHCv2 UDP [RFC5225] */
148 ROHC_ESP = 0x0003, /* ROHC ESP [RFC3095] */
149 ROHCV2_ESP = 0x0103, /* ROHCv2 ESP [RFC5225] */
150 ROHC_IP = 0x0004, /* ROHC IP [RFC3843] */
151 ROHCV2_IP = 0x0104, /* ROHCv2 IP [RFC5225] */
152 ROHC_LLA = 0x0005, /* ROHC LLA [RFC4362] */
153 ROHC_LLA_WITH_R_MODE = 0x0105, /* ROHC LLA with R-mode [RFC3408] */
154 ROHC_TCP = 0x0006, /* ROHC TCP [RFC6846] */
155 ROHC_RTP_UDP_LITE = 0x0007, /* ROHC RTP/UDP-Lite [RFC4019] */
156 ROHCV2_RTP_UDP_LITE = 0x0107, /* ROHCv2 RTP/UDP-Lite [RFC5225] */
157 ROHC_UDP_LITE = 0x0008, /* ROHC UDP-Lite [RFC4019] */
158 ROHCV2_UDP_LITE = 0x0108, /* ROHCv2 UDP-Lite [RFC5225] */
159};
160
161/* According to: 3GPP TS 44.065, 6.6.2.1 Parameters (Table 7a) */
162struct gprs_sndcp_dcomp_v42bis_params {
163 uint8_t nsapi_len; /* Number of applicable NSAPIs
164 * (default 0) */
165 uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */
166 int p0; /* (default 3) */
167 int p1; /* (default 2048) */
168 int p2; /* (default 20) */
169
170};
171
172/* According to: 3GPP TS 44.065, 6.6.2.2 Assignment of DCOMP values */
173enum gprs_sndcp_dcomp_v42bis_dcomp {
174 V42BIS_DCOMP1, /* V.42bis enabled */
175 V42BIS_DCOMP_NUM /* Number of dcomp values */
176};
177
178/* According to: 3GPP TS 44.065, 6.6.3.1 Parameters (Table 7c) */
179struct gprs_sndcp_dcomp_v44_params {
180 uint8_t nsapi_len; /* Number of applicable NSAPIs
181 * (default 0) */
182 uint8_t nsapi[MAX_NSAPI]; /* Applicable NSAPIs (default 0) */
183 int c0; /* (default 10000000) */
184 int p0; /* (default 3) */
185 int p1t; /* Refer to subclause 6.6.3.1.4 */
186 int p1r; /* Refer to subclause 6.6.3.1.5 */
187 int p3t; /* (default 3 x p1t) */
188 int p3r; /* (default 3 x p1r) */
189};
190
191/* According to: 3GPP TS 44.065, 6.6.3.2 Assignment of DCOMP values */
192enum gprs_sndcp_dcomp_v44_dcomp {
193 V44_DCOMP1, /* Packet method compressed */
194 V44_DCOMP2, /* Multi packet method compressed */
195 V44_DCOMP_NUM /* Number of dcomp values */
196};
197
198/* Transform a list with compression fields into an SNDCP-XID message (dst) */
199int gprs_sndcp_compile_xid(uint8_t *dst, unsigned int dst_maxlen,
Philippdb142dc2016-12-22 14:15:20 +0100200 const struct llist_head *comp_fields, int version);
Philipp22611be2016-08-10 12:08:03 +0200201
202/* Transform an SNDCP-XID message (src) into a list of SNDCP-XID fields */
Philippdb142dc2016-12-22 14:15:20 +0100203struct llist_head *gprs_sndcp_parse_xid(int *version,
204 const void *ctx,
205 const uint8_t *src,
206 unsigned int src_len,
207 const struct llist_head
208 *comp_fields_req);
Philipp22611be2016-08-10 12:08:03 +0200209
210/* Find out to which compression class the specified comp-field belongs
211 * (header compression or data compression?) */
212int gprs_sndcp_get_compression_class(
213 const struct gprs_sndcp_comp_field *comp_field);
214
215/* Dump a list with SNDCP-XID fields (Debug) */
216void gprs_sndcp_dump_comp_fields(const struct llist_head *comp_fields,
217 unsigned int logl);
218