blob: 612dbca1b114faf21d5c5c7cb169c9197648298f [file] [log] [blame]
Harald Welte9b455bf2010-03-14 15:45:01 +08001/* GPRS LLC protocol implementation as per 3GPP TS 04.64 */
2
Harald Weltea2665542010-05-02 09:28:11 +02003/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte9b455bf2010-03-14 15:45:01 +08004 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01008 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
Harald Welte9b455bf2010-03-14 15:45:01 +080010 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte9b455bf2010-03-14 15:45:01 +080016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte9b455bf2010-03-14 15:45:01 +080019 *
20 */
21
22#include <errno.h>
Harald Welteeaa614c2010-05-02 11:26:34 +020023#include <stdint.h>
Max82040102016-07-06 11:59:18 +020024#include <stdbool.h>
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +010025#include <inttypes.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080026
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010027#include <osmocom/core/msgb.h>
28#include <osmocom/core/linuxlist.h>
29#include <osmocom/core/timer.h>
30#include <osmocom/core/talloc.h>
Alexander Couzens4e699a92016-07-05 11:04:27 +020031#include <osmocom/core/rate_ctr.h>
Harald Welteea34a4e2012-06-16 14:59:56 +080032#include <osmocom/gprs/gprs_bssgp.h>
Neels Hofmeyree6cfdc2017-07-13 02:03:50 +020033#include <osmocom/gsm/gsm_utils.h>
Harald Weltea2665542010-05-02 09:28:11 +020034
Neels Hofmeyr396f2e62017-09-04 15:13:25 +020035#include <osmocom/sgsn/debug.h>
36#include <osmocom/sgsn/gprs_sgsn.h>
37#include <osmocom/sgsn/gprs_gmm.h>
38#include <osmocom/sgsn/gprs_llc.h>
39#include <osmocom/sgsn/crc24.h>
40#include <osmocom/sgsn/sgsn.h>
41#include <osmocom/sgsn/gprs_llc_xid.h>
42#include <osmocom/sgsn/gprs_sndcp_comp.h>
43#include <osmocom/sgsn/gprs_sndcp.h>
Harald Welte9b455bf2010-03-14 15:45:01 +080044
Eric2f898262021-05-19 18:57:50 +020045#include <osmocom/crypt/kdf.h>
46
Pau Espin Pedrol5b6c4b82019-08-14 16:08:15 +020047const struct value_string gprs_llc_llme_state_names[] = {
48 { GPRS_LLMS_UNASSIGNED, "UNASSIGNED" },
49 { GPRS_LLMS_ASSIGNED, "ASSIGNED" },
50 { 0, NULL }
51};
52
Pau Espin Pedrol13c00002023-01-04 13:54:49 +010053const struct value_string gprs_llc_lle_state_names[] = {
54 { GPRS_LLES_UNASSIGNED, "TLLI Unassigned" },
55 { GPRS_LLES_ASSIGNED_ADM, "TLLI Assigned" },
56 { GPRS_LLES_LOCAL_EST, "Local Establishment" },
57 { GPRS_LLES_REMOTE_EST, "Remote Establishment" },
58 { GPRS_LLES_ABM, "Asynchronous Balanced Mode" },
59 { GPRS_LLES_LOCAL_REL, "Local Release" },
60 { GPRS_LLES_TIMER_REC, "Timer Recovery" },
61 { 0, NULL }
62};
63
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +020064static struct gprs_llc_llme *llme_alloc(uint32_t tlli);
Maxcaff83e2022-10-09 13:32:09 +030065static int gprs_llc_tx_xid(const struct gprs_llc_lle *lle, struct msgb *msg,
Philipp4ac3aee2016-08-10 12:24:09 +020066 int command);
Maxcaff83e2022-10-09 13:32:09 +030067static int gprs_llc_tx_dm(const struct gprs_llc_lle *lle);
Philipp4ac3aee2016-08-10 12:24:09 +020068static int gprs_llc_tx_u(struct msgb *msg, uint8_t sapi,
69 int command, enum gprs_llc_u_cmd u_cmd, int pf_bit);
70
71/* BEGIN XID RELATED */
72
73/* Generate XID message */
74static int gprs_llc_generate_xid(uint8_t *bytes, int bytes_len,
75 struct gprs_llc_xid_field *l3_xid_field,
Harald Welteaf779d22019-04-12 16:56:04 +020076 struct gprs_llc_lle *lle)
Philipp4ac3aee2016-08-10 12:24:09 +020077{
78 /* Note: Called by gprs_ll_xid_req() */
79
80 LLIST_HEAD(xid_fields);
81
82 struct gprs_llc_xid_field xid_version;
83 struct gprs_llc_xid_field xid_n201u;
84 struct gprs_llc_xid_field xid_n201i;
Harald Welte41461212019-04-12 17:01:32 +020085 uint16_t n201_u, n201_i;
Philipp4ac3aee2016-08-10 12:24:09 +020086
87 xid_version.type = GPRS_LLC_XID_T_VERSION;
88 xid_version.data = (uint8_t *) "\x00";
89 xid_version.data_len = 1;
90
Harald Welte41461212019-04-12 17:01:32 +020091 n201_u = htons(lle->params.n201_u);
Philipp4ac3aee2016-08-10 12:24:09 +020092 xid_n201u.type = GPRS_LLC_XID_T_N201_U;
Harald Welte41461212019-04-12 17:01:32 +020093 xid_n201u.data = (uint8_t *) &n201_u;
Philipp4ac3aee2016-08-10 12:24:09 +020094 xid_n201u.data_len = 2;
95
Harald Welte41461212019-04-12 17:01:32 +020096 n201_i = htons(lle->params.n201_i);
Philipp4ac3aee2016-08-10 12:24:09 +020097 xid_n201i.type = GPRS_LLC_XID_T_N201_I;
Harald Welte41461212019-04-12 17:01:32 +020098 xid_n201i.data = (uint8_t *) &n201_i;
Philipp4ac3aee2016-08-10 12:24:09 +020099 xid_n201i.data_len = 2;
100
101 /* Add locally managed XID Fields */
Philipp4ac3aee2016-08-10 12:24:09 +0200102 llist_add(&xid_version.list, &xid_fields);
Philippf788d932016-12-05 12:44:19 +0100103 llist_add(&xid_n201u.list, &xid_fields);
104 llist_add(&xid_n201i.list, &xid_fields);
Philipp4ac3aee2016-08-10 12:24:09 +0200105
106 /* Append layer 3 XID field (if present) */
107 if (l3_xid_field) {
108 /* Enforce layer 3 XID type (just to be sure) */
109 l3_xid_field->type = GPRS_LLC_XID_T_L3_PAR;
110
111 /* Add Layer 3 XID field to the list */
112 llist_add(&l3_xid_field->list, &xid_fields);
113 }
114
115 /* Store generated XID for later reference */
Harald Welteaf779d22019-04-12 16:56:04 +0200116 talloc_free(lle->xid);
117 lle->xid = gprs_llc_copy_xid(lle->llme, &xid_fields);
Philipp4ac3aee2016-08-10 12:24:09 +0200118
119 return gprs_llc_compile_xid(bytes, bytes_len, &xid_fields);
120}
121
122/* Generate XID message that will cause the GMM to reset */
123static int gprs_llc_generate_xid_for_gmm_reset(uint8_t *bytes,
124 int bytes_len, uint32_t iov_ui,
Harald Welteaf779d22019-04-12 16:56:04 +0200125 struct gprs_llc_lle *lle)
Philipp4ac3aee2016-08-10 12:24:09 +0200126{
127 /* Called by gprs_llgmm_reset() and
128 * gprs_llgmm_reset_oldmsg() */
129
130 LLIST_HEAD(xid_fields);
131
132 struct gprs_llc_xid_field xid_reset;
133 struct gprs_llc_xid_field xid_iovui;
134
135 /* First XID component must be RESET */
136 xid_reset.type = GPRS_LLC_XID_T_RESET;
137 xid_reset.data = NULL;
138 xid_reset.data_len = 0;
139
140 /* Add new IOV-UI */
141 xid_iovui.type = GPRS_LLC_XID_T_IOV_UI;
142 xid_iovui.data = (uint8_t *) & iov_ui;
143 xid_iovui.data_len = 4;
144
145 /* Add locally managed XID Fields */
146 llist_add(&xid_iovui.list, &xid_fields);
147 llist_add(&xid_reset.list, &xid_fields);
148
149 /* Store generated XID for later reference */
Harald Welteaf779d22019-04-12 16:56:04 +0200150 talloc_free(lle->xid);
151 lle->xid = gprs_llc_copy_xid(lle->llme, &xid_fields);
Philipp4ac3aee2016-08-10 12:24:09 +0200152
153 return gprs_llc_compile_xid(bytes, bytes_len, &xid_fields);
154}
155
156/* Process an incoming XID confirmation */
157static int gprs_llc_process_xid_conf(uint8_t *bytes, int bytes_len,
158 struct gprs_llc_lle *lle)
159{
160 /* Note: This function handles the response of a network originated
Philipp532480a2016-12-23 11:05:11 +0100161 * XID-Request. There XID messages reflected by the MS are analyzed
Philipp4ac3aee2016-08-10 12:24:09 +0200162 * and processed here. The caller is called by rx_llc_xid(). */
163
164 struct llist_head *xid_fields;
165 struct gprs_llc_xid_field *xid_field;
Philippf1f34362016-08-26 17:00:21 +0200166 struct gprs_llc_xid_field *xid_field_request;
167 struct gprs_llc_xid_field *xid_field_request_l3 = NULL;
168
169 /* Pick layer3 XID from the XID request we have sent last */
Harald Welteaf779d22019-04-12 16:56:04 +0200170 if (lle->xid) {
171 llist_for_each_entry(xid_field_request, lle->xid, list) {
Philippf1f34362016-08-26 17:00:21 +0200172 if (xid_field_request->type == GPRS_LLC_XID_T_L3_PAR)
173 xid_field_request_l3 = xid_field_request;
174 }
175 }
Philipp4ac3aee2016-08-10 12:24:09 +0200176
177 /* Parse and analyze XID-Response */
178 xid_fields = gprs_llc_parse_xid(NULL, bytes, bytes_len);
179
180 if (xid_fields) {
181
182 gprs_llc_dump_xid_fields(xid_fields, LOGL_DEBUG);
183 llist_for_each_entry(xid_field, xid_fields, list) {
184
185 /* Forward SNDCP-XID fields to Layer 3 (SNDCP) */
Philippf1f34362016-08-26 17:00:21 +0200186 if (xid_field->type == GPRS_LLC_XID_T_L3_PAR &&
187 xid_field_request_l3) {
188 sndcp_sn_xid_conf(xid_field,
189 xid_field_request_l3, lle);
Philipp4ac3aee2016-08-10 12:24:09 +0200190 }
191
192 /* Process LLC-XID fields: */
193 else {
194
195 /* FIXME: Do something more useful with the
196 * echoed XID-Information. Currently we
197 * just ignore the response completely and
198 * by doing so we blindly accept any changes
199 * the MS might have done to the our XID
200 * inquiry. There is a remainig risk of
201 * malfunction! */
202 LOGP(DLLC, LOGL_NOTICE,
Max549ebc72016-11-18 14:07:04 +0100203 "Ignoring XID-Field: XID: type %s, data_len=%d, data=%s\n",
204 get_value_string(gprs_llc_xid_type_names,
205 xid_field->type),
206 xid_field->data_len,
Philipp4ac3aee2016-08-10 12:24:09 +0200207 osmo_hexdump_nospc(xid_field->data,
208 xid_field->data_len));
209 }
210 }
211 talloc_free(xid_fields);
212 }
213
214 /* Flush pending XID fields */
Harald Welteaf779d22019-04-12 16:56:04 +0200215 talloc_free(lle->xid);
216 lle->xid = NULL;
Philipp4ac3aee2016-08-10 12:24:09 +0200217
218 return 0;
219}
220
221/* Process an incoming XID indication and generate an appropiate response */
222static int gprs_llc_process_xid_ind(uint8_t *bytes_request,
223 int bytes_request_len,
224 uint8_t *bytes_response,
225 int bytes_response_maxlen,
Maxcaff83e2022-10-09 13:32:09 +0300226 const struct gprs_llc_lle *lle)
Philipp4ac3aee2016-08-10 12:24:09 +0200227{
228 /* Note: This function computes the response that is sent back to the
Philipp532480a2016-12-23 11:05:11 +0100229 * MS when a mobile originated XID is received. The function is
Philipp4ac3aee2016-08-10 12:24:09 +0200230 * called by rx_llc_xid() */
231
232 int rc = -EINVAL;
233
234 struct llist_head *xid_fields;
235 struct llist_head *xid_fields_response;
236
237 struct gprs_llc_xid_field *xid_field;
238 struct gprs_llc_xid_field *xid_field_response;
239
Philipp4ac3aee2016-08-10 12:24:09 +0200240 /* Parse and analyze XID-Request */
241 xid_fields =
242 gprs_llc_parse_xid(lle->llme, bytes_request, bytes_request_len);
243 if (xid_fields) {
244 xid_fields_response = talloc_zero(lle->llme, struct llist_head);
245 INIT_LLIST_HEAD(xid_fields_response);
246 gprs_llc_dump_xid_fields(xid_fields, LOGL_DEBUG);
247
248 /* Process LLC-XID fields: */
249 llist_for_each_entry(xid_field, xid_fields, list) {
250
251 if (xid_field->type != GPRS_LLC_XID_T_L3_PAR) {
252 /* FIXME: Check the incoming XID parameters for
253 * for validity. Currently we just blindly
254 * accept all XID fields by just echoing them.
255 * There is a remaining risk of malfunction
Philipp532480a2016-12-23 11:05:11 +0100256 * when a MS submits values which defer from
Philipp4ac3aee2016-08-10 12:24:09 +0200257 * the default! */
258 LOGP(DLLC, LOGL_NOTICE,
Max549ebc72016-11-18 14:07:04 +0100259 "Echoing XID-Field: XID: type %s, data_len=%d, data=%s\n",
260 get_value_string(gprs_llc_xid_type_names,
261 xid_field->type),
262 xid_field->data_len,
Philipp4ac3aee2016-08-10 12:24:09 +0200263 osmo_hexdump_nospc(xid_field->data,
264 xid_field->data_len));
265 xid_field_response =
266 gprs_llc_dup_xid_field
267 (lle->llme, xid_field);
268 llist_add(&xid_field_response->list,
269 xid_fields_response);
270 }
271 }
272
Philippf1f34362016-08-26 17:00:21 +0200273 /* Forward SNDCP-XID fields to Layer 3 (SNDCP) */
274 llist_for_each_entry(xid_field, xid_fields, list) {
275 if (xid_field->type == GPRS_LLC_XID_T_L3_PAR) {
276
277 xid_field_response =
278 talloc_zero(lle->llme,
279 struct gprs_llc_xid_field);
280 rc = sndcp_sn_xid_ind(xid_field,
281 xid_field_response, lle);
282 if (rc == 0)
283 llist_add(&xid_field_response->list,
284 xid_fields_response);
285 else
286 talloc_free(xid_field_response);
287 }
288 }
289
Philipp4ac3aee2016-08-10 12:24:09 +0200290 rc = gprs_llc_compile_xid(bytes_response,
291 bytes_response_maxlen,
292 xid_fields_response);
293 talloc_free(xid_fields_response);
294 talloc_free(xid_fields);
295 }
296
297 return rc;
298}
299
Philipp532480a2016-12-23 11:05:11 +0100300/* Dispatch XID indications and responses comming from the MS */
Philipp4ac3aee2016-08-10 12:24:09 +0200301static void rx_llc_xid(struct gprs_llc_lle *lle,
Maxcaff83e2022-10-09 13:32:09 +0300302 const struct gprs_llc_hdr_parsed *gph)
Philipp4ac3aee2016-08-10 12:24:09 +0200303{
304 uint8_t response[1024];
305 int response_len;
306
307 /* FIXME: 8.5.3.3: check if XID is invalid */
308 if (gph->is_cmd) {
309 LOGP(DLLC, LOGL_NOTICE,
Philipp532480a2016-12-23 11:05:11 +0100310 "Received XID indication from MS.\n");
Philipp4ac3aee2016-08-10 12:24:09 +0200311
312 struct msgb *resp;
313 uint8_t *xid;
314 resp = msgb_alloc_headroom(4096, 1024, "LLC_XID");
315
316 response_len =
317 gprs_llc_process_xid_ind(gph->data, gph->data_len,
318 response, sizeof(response),
319 lle);
Philippf1f34362016-08-26 17:00:21 +0200320 if (response_len < 0) {
321 LOGP(DLLC, LOGL_ERROR,
322 "invalid XID indication received!\n");
323 } else {
324 xid = msgb_put(resp, response_len);
325 memcpy(xid, response, response_len);
326 }
Philipp4ac3aee2016-08-10 12:24:09 +0200327 gprs_llc_tx_xid(lle, resp, 0);
328 } else {
329 LOGP(DLLC, LOGL_NOTICE,
Philipp532480a2016-12-23 11:05:11 +0100330 "Received XID confirmation from MS.\n");
Philipp4ac3aee2016-08-10 12:24:09 +0200331 gprs_llc_process_xid_conf(gph->data, gph->data_len, lle);
332 /* FIXME: if we had sent a XID reset, send
333 * LLGMM-RESET.conf to GMM */
334 }
335}
336
Philipp4ac3aee2016-08-10 12:24:09 +0200337/* Set of LL-XID negotiation (See also: TS 101 351, Section 7.2.2.4) */
338int gprs_ll_xid_req(struct gprs_llc_lle *lle,
339 struct gprs_llc_xid_field *l3_xid_field)
340{
341 /* Note: This functions is calle from gprs_sndcp.c */
342
343 uint8_t xid_bytes[1024];;
344 int xid_bytes_len;
345 uint8_t *xid;
346 struct msgb *msg;
Max549ebc72016-11-18 14:07:04 +0100347 const char *ftype;
Philipp4ac3aee2016-08-10 12:24:09 +0200348
349 /* Generate XID */
350 xid_bytes_len =
Harald Welteaf779d22019-04-12 16:56:04 +0200351 gprs_llc_generate_xid(xid_bytes, sizeof(xid_bytes), l3_xid_field, lle);
Philipp4ac3aee2016-08-10 12:24:09 +0200352
353 /* Only perform XID sending if the XID message contains something */
354 if (xid_bytes_len > 0) {
355 /* Transmit XID bytes */
356 msg = msgb_alloc_headroom(4096, 1024, "LLC_XID");
357 xid = msgb_put(msg, xid_bytes_len);
358 memcpy(xid, xid_bytes, xid_bytes_len);
Max549ebc72016-11-18 14:07:04 +0100359 if (l3_xid_field)
360 ftype = get_value_string(gprs_llc_xid_type_names,
361 l3_xid_field->type);
362 else
363 ftype = "NULL";
364 LOGP(DLLC, LOGL_NOTICE, "Sending XID type %s (%d bytes) request"
Philipp532480a2016-12-23 11:05:11 +0100365 " to MS...\n", ftype, xid_bytes_len);
Philipp4ac3aee2016-08-10 12:24:09 +0200366 gprs_llc_tx_xid(lle, msg, 1);
367 } else {
368 LOGP(DLLC, LOGL_ERROR,
369 "XID-Message generation failed, XID not sent!\n");
370 return -EINVAL;
371 }
372
373 return 0;
374}
375/* END XID RELATED */
376
377
378
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +0200379
Harald Weltefaa70ff2012-06-17 09:31:16 +0800380/* Entry function from upper level (LLC), asking us to transmit a BSSGP PDU
381 * to a remote MS (identified by TLLI) at a BTS identified by its BVCI and NSEI */
382static int _bssgp_tx_dl_ud(struct msgb *msg, struct sgsn_mm_ctx *mmctx)
383{
384 struct bssgp_dl_ud_par dup;
385 const uint8_t qos_profile_default[3] = { 0x00, 0x00, 0x20 };
386
Harald Welte8c004962012-07-04 21:53:12 +0200387 memset(&dup, 0, sizeof(dup));
388 /* before we have received some identity from the MS, we might
389 * not yet have a MMC context (e.g. XID negotiation of primarly
Philipp4ac3aee2016-08-10 12:24:09 +0200390 * LLC connection from GMM sapi). */
Harald Welte8c004962012-07-04 21:53:12 +0200391 if (mmctx) {
Alexander Couzensd3c3dde2020-09-18 18:28:33 +0200392 /* In rare cases the LLME is NULL in those cases don't
393 * use the mm radio capabilities */
Harald Welte8c004962012-07-04 21:53:12 +0200394 dup.imsi = mmctx->imsi;
Alexander Couzensd3c3dde2020-09-18 18:28:33 +0200395 if (mmctx->gb.llme) {
396 dup.drx_parms = mmctx->drx_parms;
397 dup.ms_ra_cap.len = mmctx->ms_radio_access_capa.len;
398 dup.ms_ra_cap.v = mmctx->ms_radio_access_capa.buf;
Holger Hans Peter Freyther7e0fec12013-07-29 10:09:12 +0200399
Alexander Couzensd3c3dde2020-09-18 18:28:33 +0200400 /* make sure we only send it to the right llme */
401 if (!(msgb_tlli(msg) == mmctx->gb.llme->tlli
402 || msgb_tlli(msg) == mmctx->gb.llme->old_tlli)) {
403 LOGP(DLLC, LOGL_ERROR,
404 "_bssgp_tx_dl_ud(): Attempt to send Downlink Unitdata to wrong LLME:"
405 " msgb_tlli=0x%x mmctx->gb.llme->tlli=0x%x ->old_tlli=0x%x\n",
406 msgb_tlli(msg), mmctx->gb.llme->tlli, mmctx->gb.llme->old_tlli);
407 msgb_free(msg);
408 return -EINVAL;
409 }
Neels Hofmeyr188a91c2017-12-27 17:29:04 +0100410 }
Harald Welte8c004962012-07-04 21:53:12 +0200411 }
Harald Weltefaa70ff2012-06-17 09:31:16 +0800412 memcpy(&dup.qos_profile, qos_profile_default,
413 sizeof(qos_profile_default));
414
Harald Weltece95b272012-06-17 13:04:02 +0800415 return bssgp_tx_dl_ud(msg, 1000, &dup);
Harald Weltefaa70ff2012-06-17 09:31:16 +0800416}
417
418
Harald Welte1d9d9442010-06-03 07:11:04 +0200419/* Section 8.9.9 LLC layer parameter default values */
Daniel Willmann46d13262014-06-27 17:05:48 +0200420static const struct gprs_llc_params llc_default_params[NUM_SAPIS] = {
Harald Welte1d9d9442010-06-03 07:11:04 +0200421 [1] = {
422 .t200_201 = 5,
423 .n200 = 3,
424 .n201_u = 400,
425 },
426 [2] = {
427 .t200_201 = 5,
428 .n200 = 3,
429 .n201_u = 270,
430 },
431 [3] = {
432 .iov_i_exp = 27,
433 .t200_201 = 5,
434 .n200 = 3,
435 .n201_u = 500,
436 .n201_i = 1503,
437 .mD = 1520,
438 .mU = 1520,
439 .kD = 16,
440 .kU = 16,
441 },
442 [5] = {
443 .iov_i_exp = 27,
444 .t200_201 = 10,
445 .n200 = 3,
446 .n201_u = 500,
447 .n201_i = 1503,
448 .mD = 760,
449 .mU = 760,
450 .kD = 8,
451 .kU = 8,
452 },
453 [7] = {
454 .t200_201 = 20,
455 .n200 = 3,
456 .n201_u = 270,
457 },
458 [8] = {
459 .t200_201 = 20,
460 .n200 = 3,
461 .n201_u = 270,
462 },
463 [9] = {
464 .iov_i_exp = 27,
465 .t200_201 = 20,
466 .n200 = 3,
467 .n201_u = 500,
468 .n201_i = 1503,
469 .mD = 380,
470 .mU = 380,
471 .kD = 4,
472 .kU = 4,
473 },
474 [11] = {
475 .iov_i_exp = 27,
476 .t200_201 = 40,
477 .n200 = 3,
478 .n201_u = 500,
479 .n201_i = 1503,
480 .mD = 190,
481 .mU = 190,
482 .kD = 2,
483 .kU = 2,
484 },
485};
486
Harald Welte807a5d82010-06-01 11:53:01 +0200487LLIST_HEAD(gprs_llc_llmes);
Harald Weltea2665542010-05-02 09:28:11 +0200488void *llc_tall_ctx;
489
490/* lookup LLC Entity based on DLCI (TLLI+SAPI tuple) */
Holger Hans Peter Freyther012a7ee2013-07-29 09:06:46 +0200491static struct gprs_llc_lle *lle_by_tlli_sapi(const uint32_t tlli, uint8_t sapi)
Harald Weltea2665542010-05-02 09:28:11 +0200492{
Harald Welte807a5d82010-06-01 11:53:01 +0200493 struct gprs_llc_llme *llme;
Harald Weltea2665542010-05-02 09:28:11 +0200494
Harald Welte807a5d82010-06-01 11:53:01 +0200495 llist_for_each_entry(llme, &gprs_llc_llmes, list) {
496 if (llme->tlli == tlli || llme->old_tlli == tlli)
497 return &llme->lle[sapi];
Harald Weltea2665542010-05-02 09:28:11 +0200498 }
499 return NULL;
500}
501
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +0200502struct gprs_llc_lle *gprs_lle_get_or_create(const uint32_t tlli, uint8_t sapi)
503{
504 struct gprs_llc_llme *llme;
505 struct gprs_llc_lle *lle;
506
507 lle = lle_by_tlli_sapi(tlli, sapi);
508 if (lle)
509 return lle;
510
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +0200511 LOGP(DLLC, LOGL_NOTICE, "LLC: unknown TLLI 0x%08x, "
512 "creating LLME on the fly\n", tlli);
513 llme = llme_alloc(tlli);
514 lle = &llme->lle[sapi];
515 return lle;
516}
517
518struct llist_head *gprs_llme_list(void)
519{
520 return &gprs_llc_llmes;
521}
522
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +0200523/* lookup LLC Entity for RX based on DLCI (TLLI+SAPI tuple) */
524static struct gprs_llc_lle *lle_for_rx_by_tlli_sapi(const uint32_t tlli,
525 uint8_t sapi, enum gprs_llc_cmd cmd)
526{
527 struct gprs_llc_lle *lle;
528
529 /* We already know about this TLLI */
530 lle = lle_by_tlli_sapi(tlli, sapi);
531 if (lle)
532 return lle;
533
534 /* Maybe it is a routing area update but we already know this sapi? */
535 if (gprs_tlli_type(tlli) == TLLI_FOREIGN) {
Jacob Erlbeck3fbf0a32016-01-04 18:43:32 +0100536 lle = lle_by_tlli_sapi(tlli, sapi);
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +0200537 if (lle) {
538 LOGP(DLLC, LOGL_NOTICE,
539 "LLC RX: Found a local entry for TLLI 0x%08x\n",
540 tlli);
541 return lle;
542 }
543 }
544
545 /* 7.2.1.1 LLC belonging to unassigned TLLI+SAPI shall be discarded,
546 * except UID and XID frames with SAPI=1 */
547 if (sapi == GPRS_SAPI_GMM &&
548 (cmd == GPRS_LLC_XID || cmd == GPRS_LLC_UI)) {
549 struct gprs_llc_llme *llme;
550 /* FIXME: don't use the TLLI but the 0xFFFF unassigned? */
551 llme = llme_alloc(tlli);
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +0100552 LOGGBP(llme, DLLC, LOGL_NOTICE, "LLC RX: unknown TLLI 0x%08x, "
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +0200553 "creating LLME on the fly\n", tlli);
554 lle = &llme->lle[sapi];
555 return lle;
556 }
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +0200557
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +0200558 LOGP(DLLC, LOGL_NOTICE,
559 "unknown TLLI(0x%08x)/SAPI(%d): Silently dropping\n",
560 tlli, sapi);
561 return NULL;
562}
563
Harald Welte1d9d9442010-06-03 07:11:04 +0200564static void lle_init(struct gprs_llc_llme *llme, uint8_t sapi)
Harald Weltea2665542010-05-02 09:28:11 +0200565{
Harald Welte807a5d82010-06-01 11:53:01 +0200566 struct gprs_llc_lle *lle = &llme->lle[sapi];
Harald Weltea2665542010-05-02 09:28:11 +0200567
Harald Welte807a5d82010-06-01 11:53:01 +0200568 lle->llme = llme;
569 lle->sapi = sapi;
570 lle->state = GPRS_LLES_UNASSIGNED;
571
Harald Welte1d9d9442010-06-03 07:11:04 +0200572 /* Initialize according to parameters */
573 memcpy(&lle->params, &llc_default_params[sapi], sizeof(lle->params));
Harald Welte807a5d82010-06-01 11:53:01 +0200574}
575
576static struct gprs_llc_llme *llme_alloc(uint32_t tlli)
577{
578 struct gprs_llc_llme *llme;
579 uint32_t i;
580
581 llme = talloc_zero(llc_tall_ctx, struct gprs_llc_llme);
582 if (!llme)
Harald Weltea2665542010-05-02 09:28:11 +0200583 return NULL;
584
Harald Welte807a5d82010-06-01 11:53:01 +0200585 llme->tlli = tlli;
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +0200586 llme->old_tlli = TLLI_UNASSIGNED;
Harald Welte807a5d82010-06-01 11:53:01 +0200587 llme->state = GPRS_LLMS_UNASSIGNED;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100588 llme->age_timestamp = GPRS_LLME_RESET_AGE;
Max5aa51962016-07-06 11:33:04 +0200589 llme->cksn = GSM_KEY_SEQ_INVAL;
Harald Weltea2665542010-05-02 09:28:11 +0200590
Harald Welte807a5d82010-06-01 11:53:01 +0200591 for (i = 0; i < ARRAY_SIZE(llme->lle); i++)
592 lle_init(llme, i);
593
594 llist_add(&llme->list, &gprs_llc_llmes);
595
Philippf1f34362016-08-26 17:00:21 +0200596 llme->comp.proto = gprs_sndcp_comp_alloc(llme);
597 llme->comp.data = gprs_sndcp_comp_alloc(llme);
598
Harald Welte807a5d82010-06-01 11:53:01 +0200599 return llme;
Harald Weltea2665542010-05-02 09:28:11 +0200600}
601
Harald Weltef7fef482010-06-28 22:18:26 +0200602static void llme_free(struct gprs_llc_llme *llme)
603{
Oliver Smithf7642852021-12-07 13:16:17 +0100604 gprs_sndcp_sm_deactivate_ind_by_llme(llme);
Philippf1f34362016-08-26 17:00:21 +0200605 gprs_sndcp_comp_free(llme->comp.proto);
606 gprs_sndcp_comp_free(llme->comp.data);
Harald Weltef7fef482010-06-28 22:18:26 +0200607 llist_del(&llme->list);
608 talloc_free(llme);
609}
610
Holger Hans Peter Freyther744568b2014-04-04 12:47:32 +0200611#if 0
612/* FIXME: Unused code... */
Harald Welte9b455bf2010-03-14 15:45:01 +0800613static void t200_expired(void *data)
614{
615 struct gprs_llc_lle *lle = data;
616
617 /* 8.5.1.3: Expiry of T200 */
618
Harald Welte1d9d9442010-06-03 07:11:04 +0200619 if (lle->retrans_ctr >= lle->params.n200) {
Harald Welte9b455bf2010-03-14 15:45:01 +0800620 /* FIXME: LLGM-STATUS-IND, LL-RELEASE-IND/CNF */
Harald Welte807a5d82010-06-01 11:53:01 +0200621 lle->state = GPRS_LLES_ASSIGNED_ADM;
Harald Welte9b455bf2010-03-14 15:45:01 +0800622 }
623
624 switch (lle->state) {
Harald Welte807a5d82010-06-01 11:53:01 +0200625 case GPRS_LLES_LOCAL_EST:
Harald Welte1ae09c72010-05-13 19:22:55 +0200626 /* FIXME: retransmit SABM */
627 /* FIXME: re-start T200 */
Harald Welte9b455bf2010-03-14 15:45:01 +0800628 lle->retrans_ctr++;
629 break;
Harald Welte807a5d82010-06-01 11:53:01 +0200630 case GPRS_LLES_LOCAL_REL:
Harald Welte1ae09c72010-05-13 19:22:55 +0200631 /* FIXME: retransmit DISC */
632 /* FIXME: re-start T200 */
Harald Welte9b455bf2010-03-14 15:45:01 +0800633 lle->retrans_ctr++;
634 break;
Holger Hans Peter Freyther744568b2014-04-04 12:47:32 +0200635 default:
636 LOGP(DLLC, LOGL_ERROR, "LLC unhandled state: %d\n", lle->state);
637 break;
Harald Welte9b455bf2010-03-14 15:45:01 +0800638 }
639
640}
641
642static void t201_expired(void *data)
643{
644 struct gprs_llc_lle *lle = data;
645
Harald Welte1d9d9442010-06-03 07:11:04 +0200646 if (lle->retrans_ctr < lle->params.n200) {
Harald Welte1ae09c72010-05-13 19:22:55 +0200647 /* FIXME: transmit apropriate supervisory frame (8.6.4.1) */
648 /* FIXME: set timer T201 */
Harald Welte9b455bf2010-03-14 15:45:01 +0800649 lle->retrans_ctr++;
650 }
651}
Holger Hans Peter Freyther744568b2014-04-04 12:47:32 +0200652#endif
Harald Welte9b455bf2010-03-14 15:45:01 +0800653
Harald Welte10997d02010-05-03 12:28:12 +0200654int gprs_llc_tx_u(struct msgb *msg, uint8_t sapi, int command,
655 enum gprs_llc_u_cmd u_cmd, int pf_bit)
656{
657 uint8_t *fcs, *llch;
658 uint8_t addr, ctrl;
659 uint32_t fcs_calc;
660
661 /* Identifiers from UP: (TLLI, SAPI) + (BVCI, NSEI) */
662
663 /* Address Field */
664 addr = sapi & 0xf;
665 if (command)
666 addr |= 0x40;
667
668 /* 6.3 Figure 8 */
669 ctrl = 0xe0 | u_cmd;
670 if (pf_bit)
671 ctrl |= 0x10;
672
673 /* prepend LLC UI header */
674 llch = msgb_push(msg, 2);
675 llch[0] = addr;
676 llch[1] = ctrl;
677
678 /* append FCS to end of frame */
679 fcs = msgb_put(msg, 3);
680 fcs_calc = gprs_llc_fcs(llch, fcs - llch);
681 fcs[0] = fcs_calc & 0xff;
682 fcs[1] = (fcs_calc >> 8) & 0xff;
683 fcs[2] = (fcs_calc >> 16) & 0xff;
684
685 /* Identifiers passed down: (BVCI, NSEI) */
686
Pau Espin Pedrola33f0062021-06-04 17:27:03 +0200687 rate_ctr_inc(rate_ctr_group_get_ctr(sgsn->rate_ctrs, CTR_LLC_DL_PACKETS));
688 rate_ctr_add(rate_ctr_group_get_ctr(sgsn->rate_ctrs, CTR_LLC_DL_BYTES), msg->len);
Alexander Couzens4e699a92016-07-05 11:04:27 +0200689
Harald Welte1ae09c72010-05-13 19:22:55 +0200690 /* Send BSSGP-DL-UNITDATA.req */
Harald Welteb1fd9022012-06-17 12:16:31 +0800691 return _bssgp_tx_dl_ud(msg, NULL);
Harald Welte10997d02010-05-03 12:28:12 +0200692}
693
694/* Send XID response to LLE */
Maxcaff83e2022-10-09 13:32:09 +0300695static int gprs_llc_tx_xid(const struct gprs_llc_lle *lle, struct msgb *msg,
Harald Welte0c1a3032011-10-16 18:49:05 +0200696 int command)
Harald Welte10997d02010-05-03 12:28:12 +0200697{
698 /* copy identifiers from LLE to ensure lower layers can route */
Harald Welte807a5d82010-06-01 11:53:01 +0200699 msgb_tlli(msg) = lle->llme->tlli;
700 msgb_bvci(msg) = lle->llme->bvci;
701 msgb_nsei(msg) = lle->llme->nsei;
Harald Welte10997d02010-05-03 12:28:12 +0200702
Harald Welte0c1a3032011-10-16 18:49:05 +0200703 return gprs_llc_tx_u(msg, lle->sapi, command, GPRS_LLC_U_XID, 1);
Harald Welte10997d02010-05-03 12:28:12 +0200704}
705
Maxcaff83e2022-10-09 13:32:09 +0300706static int gprs_llc_tx_dm(const struct gprs_llc_lle *lle)
Harald Welte1f60bbe2019-04-23 23:21:14 +0200707{
708 struct msgb *msg = msgb_alloc_headroom(4096, 1024, "LLC_DM");
709
710 /* copy identifiers from LLE to ensure lower layers can route */
711 msgb_tlli(msg) = lle->llme->tlli;
712 msgb_bvci(msg) = lle->llme->bvci;
713 msgb_nsei(msg) = lle->llme->nsei;
714
715 return gprs_llc_tx_u(msg, lle->sapi, 0, GPRS_LLC_U_DM_RESP, 1);
716}
717
Max1de15912016-07-11 12:42:12 +0200718/* encrypt information field + FCS, if needed! */
Maxcaff83e2022-10-09 13:32:09 +0300719static int apply_gea(const struct gprs_llc_lle *lle, uint16_t crypt_len, uint16_t nu,
Max1de15912016-07-11 12:42:12 +0200720 uint32_t oc, uint8_t sapi, uint8_t *fcs, uint8_t *data)
721{
722 uint8_t cipher_out[GSM0464_CIPH_MAX_BLOCK];
723
724 if (lle->llme->algo == GPRS_ALGO_GEA0)
725 return -EINVAL;
726
727 /* Compute the 'Input' Paraemeter */
Dieter Spaarb572d7c2016-07-11 12:48:07 +0200728 uint32_t fcs_calc, iv = gprs_cipher_gen_input_ui(lle->llme->iov_ui, sapi,
Max1de15912016-07-11 12:42:12 +0200729 nu, oc);
730 /* Compute gamma that we need to XOR with the data */
731 int r = gprs_cipher_run(cipher_out, crypt_len, lle->llme->algo,
732 lle->llme->kc, iv,
733 fcs ? GPRS_CIPH_SGSN2MS : GPRS_CIPH_MS2SGSN);
734 if (r < 0) {
735 LOGP(DLLC, LOGL_ERROR, "Error producing %s gamma for UI "
736 "frame: %d\n", get_value_string(gprs_cipher_names,
737 lle->llme->algo), r);
738 return -ENOMSG;
739 }
740
741 if (fcs) {
Dieter Spaarb572d7c2016-07-11 12:48:07 +0200742 /* Mark frame as encrypted and update FCS */
743 data[2] |= 0x02;
744 fcs_calc = gprs_llc_fcs(data, fcs - data);
745 fcs[0] = fcs_calc & 0xff;
746 fcs[1] = (fcs_calc >> 8) & 0xff;
747 fcs[2] = (fcs_calc >> 16) & 0xff;
Max1de15912016-07-11 12:42:12 +0200748 data += 3;
749 }
750
751 /* XOR the cipher output with the data */
752 for (r = 0; r < crypt_len; r++)
753 *(data + r) ^= cipher_out[r];
754
755 return 0;
756}
757
Max82040102016-07-06 11:59:18 +0200758/* Transmit a UI frame over the given SAPI:
759 'encryptable' indicates whether particular message can be encrypted according
760 to 3GPP TS 24.008 § 4.7.1.2
761 */
Harald Welte56a01452010-05-31 22:12:30 +0200762int gprs_llc_tx_ui(struct msgb *msg, uint8_t sapi, int command,
Max82040102016-07-06 11:59:18 +0200763 struct sgsn_mm_ctx *mmctx, bool encryptable)
Harald Welte9b455bf2010-03-14 15:45:01 +0800764{
Harald Weltee6afd602010-05-02 11:19:37 +0200765 struct gprs_llc_lle *lle;
Harald Welteeaa614c2010-05-02 11:26:34 +0200766 uint8_t *fcs, *llch;
767 uint8_t addr, ctrl[2];
768 uint32_t fcs_calc;
769 uint16_t nu = 0;
Harald Welted07b4f92010-06-30 23:07:59 +0200770 uint32_t oc;
Harald Welte9b455bf2010-03-14 15:45:01 +0800771
Harald Weltee6afd602010-05-02 11:19:37 +0200772 /* Identifiers from UP: (TLLI, SAPI) + (BVCI, NSEI) */
773
774 /* look-up or create the LL Entity for this (TLLI, SAPI) tuple */
Holger Hans Peter Freyther4299c052014-10-02 21:27:24 +0200775 lle = gprs_lle_get_or_create(msgb_tlli(msg), sapi);
Harald Welte1d9d9442010-06-03 07:11:04 +0200776
777 if (msg->len > lle->params.n201_u) {
778 LOGP(DLLC, LOGL_ERROR, "Cannot Tx %u bytes (N201-U=%u)\n",
779 msg->len, lle->params.n201_u);
Holger Hans Peter Freytherf9ffd1f2014-10-10 17:35:54 +0200780 msgb_free(msg);
Harald Welte1d9d9442010-06-03 07:11:04 +0200781 return -EFBIG;
782 }
783
Max5aa51962016-07-06 11:33:04 +0200784 gprs_llme_copy_key(mmctx, lle->llme);
785
Harald Weltee6afd602010-05-02 11:19:37 +0200786 /* Update LLE's (BVCI, NSEI) tuple */
Harald Welte807a5d82010-06-01 11:53:01 +0200787 lle->llme->bvci = msgb_bvci(msg);
788 lle->llme->nsei = msgb_nsei(msg);
Harald Weltee6afd602010-05-02 11:19:37 +0200789
Harald Welted07b4f92010-06-30 23:07:59 +0200790 /* Obtain current values for N(u) and OC */
Harald Welte6bdee6a2010-05-30 21:51:58 +0200791 nu = lle->vu_send;
Harald Welted07b4f92010-06-30 23:07:59 +0200792 oc = lle->oc_ui_send;
793 /* Increment V(U) */
Harald Welte6bdee6a2010-05-30 21:51:58 +0200794 lle->vu_send = (lle->vu_send + 1) % 512;
Harald Welted07b4f92010-06-30 23:07:59 +0200795 /* Increment Overflow Counter, if needed */
796 if ((lle->vu_send + 1) / 512)
797 lle->oc_ui_send += 512;
Harald Welte6bdee6a2010-05-30 21:51:58 +0200798
Harald Welte9b455bf2010-03-14 15:45:01 +0800799 /* Address Field */
800 addr = sapi & 0xf;
801 if (command)
802 addr |= 0x40;
803
804 /* Control Field */
805 ctrl[0] = 0xc0;
806 ctrl[0] |= nu >> 6;
807 ctrl[1] = (nu << 2) & 0xfc;
808 ctrl[1] |= 0x01; /* Protected Mode */
809
810 /* prepend LLC UI header */
811 llch = msgb_push(msg, 3);
812 llch[0] = addr;
813 llch[1] = ctrl[0];
814 llch[2] = ctrl[1];
815
816 /* append FCS to end of frame */
817 fcs = msgb_put(msg, 3);
818 fcs_calc = gprs_llc_fcs(llch, fcs - llch);
819 fcs[0] = fcs_calc & 0xff;
820 fcs[1] = (fcs_calc >> 8) & 0xff;
821 fcs[2] = (fcs_calc >> 16) & 0xff;
822
Max82040102016-07-06 11:59:18 +0200823 if (lle->llme->algo != GPRS_ALGO_GEA0 && encryptable) {
Max1de15912016-07-11 12:42:12 +0200824 int rc = apply_gea(lle, fcs - llch, nu, oc, sapi, fcs, llch);
Harald Welted07b4f92010-06-30 23:07:59 +0200825 if (rc < 0) {
Holger Hans Peter Freytherf9ffd1f2014-10-10 17:35:54 +0200826 msgb_free(msg);
Harald Welted07b4f92010-06-30 23:07:59 +0200827 return rc;
828 }
Harald Welted07b4f92010-06-30 23:07:59 +0200829 }
830
Pau Espin Pedrola33f0062021-06-04 17:27:03 +0200831 rate_ctr_inc(rate_ctr_group_get_ctr(sgsn->rate_ctrs, CTR_LLC_DL_PACKETS));
832 rate_ctr_add(rate_ctr_group_get_ctr(sgsn->rate_ctrs, CTR_LLC_DL_BYTES), msg->len);
Alexander Couzens33163972016-10-04 17:53:21 +0200833
Harald Weltee6afd602010-05-02 11:19:37 +0200834 /* Identifiers passed down: (BVCI, NSEI) */
835
Harald Welte1ae09c72010-05-13 19:22:55 +0200836 /* Send BSSGP-DL-UNITDATA.req */
Harald Weltefaa70ff2012-06-17 09:31:16 +0800837 return _bssgp_tx_dl_ud(msg, mmctx);
Harald Welte9b455bf2010-03-14 15:45:01 +0800838}
839
Harald Welte9b455bf2010-03-14 15:45:01 +0800840static int gprs_llc_hdr_rx(struct gprs_llc_hdr_parsed *gph,
841 struct gprs_llc_lle *lle)
842{
843 switch (gph->cmd) {
Harald Welte1f60bbe2019-04-23 23:21:14 +0200844#if 0
845 /* we don't fully imoplement ABM, so refuse it properly (OS#3953) */
Harald Welte9b455bf2010-03-14 15:45:01 +0800846 case GPRS_LLC_SABM: /* Section 6.4.1.1 */
847 lle->v_sent = lle->v_ack = lle->v_recv = 0;
Harald Welte807a5d82010-06-01 11:53:01 +0200848 if (lle->state == GPRS_LLES_ASSIGNED_ADM) {
Harald Welte9b455bf2010-03-14 15:45:01 +0800849 /* start re-establishment (8.7.1) */
850 }
Harald Welte807a5d82010-06-01 11:53:01 +0200851 lle->state = GPRS_LLES_REMOTE_EST;
Harald Welte9b455bf2010-03-14 15:45:01 +0800852 /* FIXME: Send UA */
Harald Welte807a5d82010-06-01 11:53:01 +0200853 lle->state = GPRS_LLES_ABM;
Harald Welte9b455bf2010-03-14 15:45:01 +0800854 /* FIXME: process data */
855 break;
856 case GPRS_LLC_DISC: /* Section 6.4.1.2 */
857 /* FIXME: Send UA */
858 /* terminate ABM */
Harald Welte807a5d82010-06-01 11:53:01 +0200859 lle->state = GPRS_LLES_ASSIGNED_ADM;
Harald Welte9b455bf2010-03-14 15:45:01 +0800860 break;
861 case GPRS_LLC_UA: /* Section 6.4.1.3 */
Harald Welte807a5d82010-06-01 11:53:01 +0200862 if (lle->state == GPRS_LLES_LOCAL_EST)
863 lle->state = GPRS_LLES_ABM;
Harald Welte9b455bf2010-03-14 15:45:01 +0800864 break;
865 case GPRS_LLC_DM: /* Section 6.4.1.4: ABM cannot be performed */
Harald Welte807a5d82010-06-01 11:53:01 +0200866 if (lle->state == GPRS_LLES_LOCAL_EST)
867 lle->state = GPRS_LLES_ASSIGNED_ADM;
Harald Welte9b455bf2010-03-14 15:45:01 +0800868 break;
869 case GPRS_LLC_FRMR: /* Section 6.4.1.5 */
870 break;
Harald Welte1f60bbe2019-04-23 23:21:14 +0200871#else
872 case GPRS_LLC_SABM:
873 case GPRS_LLC_DISC:
874 /* send DM to properly signal we don't do ABM */
875 gprs_llc_tx_dm(lle);
876 break;
877#endif
Harald Welte9b455bf2010-03-14 15:45:01 +0800878 case GPRS_LLC_XID: /* Section 6.4.1.6 */
Harald Welte0c1a3032011-10-16 18:49:05 +0200879 rx_llc_xid(lle, gph);
Harald Welte9b455bf2010-03-14 15:45:01 +0800880 break;
Harald Welteebabdea2010-06-01 18:28:10 +0200881 case GPRS_LLC_UI:
Holger Hans Peter Freytherfaf1f642011-06-23 17:53:27 -0400882 if (gprs_llc_is_retransmit(gph->seq_tx, lle->vu_recv)) {
883 LOGP(DLLC, LOGL_NOTICE,
884 "TLLI=%08x dropping UI, N(U=%d) not in window V(URV(UR:%d).\n",
Holger Hans Peter Freyther2788b962010-06-23 09:48:25 +0800885 lle->llme ? lle->llme->tlli : -1,
Harald Welteebabdea2010-06-01 18:28:10 +0200886 gph->seq_tx, lle->vu_recv);
Harald Welteabadd542013-06-21 14:06:18 +0200887
888 /* HACK: non-standard recovery handling. If remote LLE
889 * is re-transmitting the same sequence number for
Harald Welte649e1ff2013-07-21 17:41:46 +0800890 * three times, don't discard the frame but pass it on
Harald Welteabadd542013-06-21 14:06:18 +0200891 * and 'learn' the new sequence number */
892 if (gph->seq_tx != lle->vu_recv_last) {
893 lle->vu_recv_last = gph->seq_tx;
894 lle->vu_recv_duplicates = 0;
895 } else {
896 lle->vu_recv_duplicates++;
897 if (lle->vu_recv_duplicates < 3)
898 return -EIO;
899 LOGP(DLLC, LOGL_NOTICE, "TLLI=%08x recovering "
900 "N(U=%d) after receiving %u duplicates\n",
901 lle->llme ? lle->llme->tlli : -1,
902 gph->seq_tx, lle->vu_recv_duplicates);
903 }
Harald Welteebabdea2010-06-01 18:28:10 +0200904 }
905 /* Increment the sequence number that we expect in the next frame */
906 lle->vu_recv = (gph->seq_tx + 1) % 512;
Harald Welted07b4f92010-06-30 23:07:59 +0200907 /* Increment Overflow Counter */
908 if ((gph->seq_tx + 1) / 512)
909 lle->oc_ui_recv += 512;
Harald Welteebabdea2010-06-01 18:28:10 +0200910 break;
Harald Welte3a0b7722019-04-23 22:48:26 +0200911 case GPRS_LLC_NULL:
912 LOGP(DLLC, LOGL_DEBUG, "TLLI=%08x sends us LLC NULL\n", lle->llme ? lle->llme->tlli : -1);
913 break;
Holger Hans Peter Freyther744568b2014-04-04 12:47:32 +0200914 default:
915 LOGP(DLLC, LOGL_NOTICE, "Unhandled command: %d\n", gph->cmd);
916 break;
Harald Welte9b455bf2010-03-14 15:45:01 +0800917 }
918
919 return 0;
920}
921
Harald Weltea2665542010-05-02 09:28:11 +0200922/* receive an incoming LLC PDU (BSSGP-UL-UNITDATA-IND, 7.2.4.2) */
Harald Welte9b455bf2010-03-14 15:45:01 +0800923int gprs_llc_rcvmsg(struct msgb *msg, struct tlv_parsed *tv)
924{
Holger Hans Peter Freyther3dccda52011-10-14 23:42:13 +0200925 struct gprs_llc_hdr *lh = (struct gprs_llc_hdr *) msgb_llch(msg);
Harald Welte9b455bf2010-03-14 15:45:01 +0800926 struct gprs_llc_hdr_parsed llhp;
Max549ebc72016-11-18 14:07:04 +0100927 struct gprs_llc_lle *lle = NULL;
Max82040102016-07-06 11:59:18 +0200928 bool drop_cipherable = false;
Harald Weltea2665542010-05-02 09:28:11 +0200929 int rc = 0;
Harald Welte9b455bf2010-03-14 15:45:01 +0800930
Harald Welte11d7c102010-05-02 11:54:55 +0200931 /* Identifiers from DOWN: NSEI, BVCI, TLLI */
932
Holger Hans Peter Freyther4752e0c2010-05-23 21:33:57 +0800933 memset(&llhp, 0, sizeof(llhp));
Holger Hans Peter Freytherfa848d42010-05-23 21:43:57 +0800934 rc = gprs_llc_hdr_parse(&llhp, (uint8_t *) lh, TLVP_LEN(tv, BSSGP_IE_LLC_PDU));
Harald Welte1ae09c72010-05-13 19:22:55 +0200935 if (rc < 0) {
Harald Welte1b170d12010-05-13 19:49:06 +0200936 LOGP(DLLC, LOGL_NOTICE, "Error during LLC header parsing\n");
Harald Welte1ae09c72010-05-13 19:22:55 +0200937 return rc;
938 }
939
Harald Welte807a5d82010-06-01 11:53:01 +0200940 switch (gprs_tlli_type(msgb_tlli(msg))) {
941 case TLLI_LOCAL:
942 case TLLI_FOREIGN:
943 case TLLI_RANDOM:
944 case TLLI_AUXILIARY:
945 break;
946 default:
947 LOGP(DLLC, LOGL_ERROR,
948 "Discarding frame with strange TLLI type\n");
949 break;
950 }
951
Harald Weltea2665542010-05-02 09:28:11 +0200952 /* find the LLC Entity for this TLLI+SAPI tuple */
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +0200953 lle = lle_for_rx_by_tlli_sapi(msgb_tlli(msg), llhp.sapi, llhp.cmd);
Jacob Erlbeck78ecaf02014-09-05 14:32:36 +0200954 if (!lle) {
955 switch (llhp.sapi) {
956 case GPRS_SAPI_SNDCP3:
957 case GPRS_SAPI_SNDCP5:
958 case GPRS_SAPI_SNDCP9:
959 case GPRS_SAPI_SNDCP11:
960 /* Ask an upper layer for help. */
Alexander Couzens58f446c2016-08-30 18:51:50 +0200961 return gsm0408_gprs_force_reattach_oldmsg(msg, NULL);
Jacob Erlbeck78ecaf02014-09-05 14:32:36 +0200962 default:
963 break;
964 }
Holger Hans Peter Freyther964a9b32013-07-30 09:29:27 +0200965 return 0;
Jacob Erlbeck78ecaf02014-09-05 14:32:36 +0200966 }
Max549ebc72016-11-18 14:07:04 +0100967 gprs_llc_hdr_dump(&llhp, lle);
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100968 /* reset age computation */
969 lle->llme->age_timestamp = GPRS_LLME_RESET_AGE;
970
Harald Welted07b4f92010-06-30 23:07:59 +0200971 /* decrypt information field + FCS, if needed! */
972 if (llhp.is_encrypted) {
Max1de15912016-07-11 12:42:12 +0200973 if (lle->llme->algo != GPRS_ALGO_GEA0) {
974 rc = apply_gea(lle, llhp.data_len + 3, llhp.seq_tx,
975 lle->oc_ui_recv, lle->sapi, NULL,
976 llhp.data);
977 if (rc < 0)
978 return rc;
Vadim Yanitskiyfb6cf322022-08-26 05:38:24 +0700979 llhp.fcs = *(llhp.data + llhp.data_len);
980 llhp.fcs |= *(llhp.data + llhp.data_len + 1) << 8;
981 llhp.fcs |= *(llhp.data + llhp.data_len + 2) << 16;
Max1de15912016-07-11 12:42:12 +0200982 } else {
Harald Welted07b4f92010-06-30 23:07:59 +0200983 LOGP(DLLC, LOGL_NOTICE, "encrypted frame for LLC that "
984 "has no KC/Algo! Dropping.\n");
985 return 0;
986 }
Harald Welted07b4f92010-06-30 23:07:59 +0200987 } else {
Max82040102016-07-06 11:59:18 +0200988 if (lle->llme->algo != GPRS_ALGO_GEA0 &&
989 lle->llme->cksn != GSM_KEY_SEQ_INVAL)
990 drop_cipherable = true;
Harald Welted07b4f92010-06-30 23:07:59 +0200991 }
992
993 /* We have to do the FCS check _after_ decryption */
Harald Welte1b8827a2010-06-30 23:15:57 +0200994 llhp.fcs_calc = gprs_llc_fcs((uint8_t *)lh, llhp.crc_length);
Harald Welted07b4f92010-06-30 23:07:59 +0200995 if (llhp.fcs != llhp.fcs_calc) {
996 LOGP(DLLC, LOGL_INFO, "Dropping frame with invalid FCS\n");
997 return -EIO;
998 }
999
Harald Welte10997d02010-05-03 12:28:12 +02001000 /* Update LLE's (BVCI, NSEI) tuple */
Harald Welte807a5d82010-06-01 11:53:01 +02001001 lle->llme->bvci = msgb_bvci(msg);
1002 lle->llme->nsei = msgb_nsei(msg);
Harald Welte10997d02010-05-03 12:28:12 +02001003
Harald Welte1ae09c72010-05-13 19:22:55 +02001004 /* Receive and Process the actual LLC frame */
Harald Welte9b455bf2010-03-14 15:45:01 +08001005 rc = gprs_llc_hdr_rx(&llhp, lle);
Harald Welte1ae09c72010-05-13 19:22:55 +02001006 if (rc < 0)
1007 return rc;
Harald Welte9b455bf2010-03-14 15:45:01 +08001008
Harald Welte37bd0212019-04-23 22:46:43 +02001009 /* there are many frame types that don't carry user information
1010 * and which hence have llhp.data = NULL */
1011 if (llhp.data) {
1012 /* set l3 layer & remove the fcs */
1013 msg->l3h = llhp.data;
1014 msgb_l3trim(msg, llhp.data_len);
1015 }
1016
Pau Espin Pedrola33f0062021-06-04 17:27:03 +02001017 rate_ctr_inc(rate_ctr_group_get_ctr(sgsn->rate_ctrs, CTR_LLC_UL_PACKETS));
1018 rate_ctr_add(rate_ctr_group_get_ctr(sgsn->rate_ctrs, CTR_LLC_UL_BYTES), msg->len);
Alexander Couzens4e699a92016-07-05 11:04:27 +02001019
Harald Welte1ae09c72010-05-13 19:22:55 +02001020 /* llhp.data is only set when we need to send LL_[UNIT]DATA_IND up */
Harald Welte22df4ac2015-08-16 15:23:32 +02001021 if (llhp.cmd == GPRS_LLC_UI && llhp.data && llhp.data_len) {
Harald Welte9b455bf2010-03-14 15:45:01 +08001022 switch (llhp.sapi) {
1023 case GPRS_SAPI_GMM:
Harald Welte1ae09c72010-05-13 19:22:55 +02001024 /* send LL_UNITDATA_IND to GMM */
Max82040102016-07-06 11:59:18 +02001025 rc = gsm0408_gprs_rcvmsg_gb(msg, lle->llme,
1026 drop_cipherable);
Harald Weltea2665542010-05-02 09:28:11 +02001027 break;
Harald Weltea2665542010-05-02 09:28:11 +02001028 case GPRS_SAPI_SNDCP3:
1029 case GPRS_SAPI_SNDCP5:
1030 case GPRS_SAPI_SNDCP9:
1031 case GPRS_SAPI_SNDCP11:
Harald Welteebabdea2010-06-01 18:28:10 +02001032 /* send LL_DATA_IND/LL_UNITDATA_IND to SNDCP */
1033 rc = sndcp_llunitdata_ind(msg, lle, llhp.data, llhp.data_len);
1034 break;
Harald Weltea2665542010-05-02 09:28:11 +02001035 case GPRS_SAPI_SMS:
1036 /* FIXME */
Harald Welteebabdea2010-06-01 18:28:10 +02001037 case GPRS_SAPI_TOM2:
1038 case GPRS_SAPI_TOM8:
1039 /* FIXME: send LL_DATA_IND/LL_UNITDATA_IND to TOM */
Harald Weltea2665542010-05-02 09:28:11 +02001040 default:
Harald Weltec6ecafe2010-05-13 19:47:50 +02001041 LOGP(DLLC, LOGL_NOTICE, "Unsupported SAPI %u\n", llhp.sapi);
Harald Weltea2665542010-05-02 09:28:11 +02001042 rc = -EINVAL;
1043 break;
Harald Welte9b455bf2010-03-14 15:45:01 +08001044 }
1045 }
1046
Harald Weltea2665542010-05-02 09:28:11 +02001047 return rc;
Harald Welte9b455bf2010-03-14 15:45:01 +08001048}
Harald Welte807a5d82010-06-01 11:53:01 +02001049
Max5aa51962016-07-06 11:33:04 +02001050/* Propagate crypto parameters MM -> LLME */
Maxcaff83e2022-10-09 13:32:09 +03001051void gprs_llme_copy_key(const struct sgsn_mm_ctx *mm, struct gprs_llc_llme *llme)
Max5aa51962016-07-06 11:33:04 +02001052{
1053 if (!mm)
1054 return;
1055 if (mm->ciph_algo != GPRS_ALGO_GEA0) {
1056 llme->algo = mm->ciph_algo;
1057 if (llme->cksn != mm->auth_triplet.key_seq &&
1058 mm->auth_triplet.key_seq != GSM_KEY_SEQ_INVAL) {
Eric2f898262021-05-19 18:57:50 +02001059
1060 /* gea4 needs kc128 */
1061 if (mm->ciph_algo == GPRS_ALGO_GEA4)
1062 osmo_kdf_kc128(mm->auth_triplet.vec.ck, mm->auth_triplet.vec.ik, llme->kc);
1063 else
1064 memcpy(llme->kc, mm->auth_triplet.vec.kc, gprs_cipher_key_length(mm->ciph_algo));
1065
Max5aa51962016-07-06 11:33:04 +02001066 llme->cksn = mm->auth_triplet.key_seq;
1067 }
1068 } else
1069 llme->cksn = GSM_KEY_SEQ_INVAL;
1070}
1071
Harald Welte807a5d82010-06-01 11:53:01 +02001072/* 04.64 Chapter 7.2.1.1 LLGMM-ASSIGN */
1073int gprs_llgmm_assign(struct gprs_llc_llme *llme,
Max5aa51962016-07-06 11:33:04 +02001074 uint32_t old_tlli, uint32_t new_tlli)
Harald Welte807a5d82010-06-01 11:53:01 +02001075{
1076 unsigned int i;
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +01001077 bool free = false;
1078
1079 LOGGBP(llme, DLLC, LOGL_NOTICE, "LLGM Assign pre (%08x => %08x)\n",
1080 old_tlli, new_tlli);
Harald Welte807a5d82010-06-01 11:53:01 +02001081
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001082 if (old_tlli == TLLI_UNASSIGNED && new_tlli != TLLI_UNASSIGNED) {
Harald Welte807a5d82010-06-01 11:53:01 +02001083 /* TLLI Assignment 8.3.1 */
1084 /* New TLLI shall be assigned and used when (re)transmitting LLC frames */
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001085 /* If old TLLI != TLLI_UNASSIGNED was assigned to LLME, then TLLI
Harald Welte807a5d82010-06-01 11:53:01 +02001086 * old is unassigned. Only TLLI new shall be accepted when
1087 * received from peer. */
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001088 if (llme->old_tlli != TLLI_UNASSIGNED) {
1089 llme->old_tlli = TLLI_UNASSIGNED;
Harald Welte875840c2010-07-01 11:54:31 +02001090 llme->tlli = new_tlli;
1091 } else {
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001092 /* If TLLI old == TLLI_UNASSIGNED was assigned to LLME, then this is
Harald Welte875840c2010-07-01 11:54:31 +02001093 * TLLI assignmemt according to 8.3.1 */
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001094 llme->old_tlli = TLLI_UNASSIGNED;
Harald Welte875840c2010-07-01 11:54:31 +02001095 llme->tlli = new_tlli;
1096 llme->state = GPRS_LLMS_ASSIGNED;
1097 /* 8.5.3.1 For all LLE's */
1098 for (i = 0; i < ARRAY_SIZE(llme->lle); i++) {
1099 struct gprs_llc_lle *l = &llme->lle[i];
1100 l->vu_send = l->vu_recv = 0;
1101 l->retrans_ctr = 0;
1102 l->state = GPRS_LLES_ASSIGNED_ADM;
1103 /* FIXME Set parameters according to table 9 */
1104 }
Harald Welte807a5d82010-06-01 11:53:01 +02001105 }
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001106 } else if (old_tlli != TLLI_UNASSIGNED && new_tlli != TLLI_UNASSIGNED) {
Harald Welte807a5d82010-06-01 11:53:01 +02001107 /* TLLI Change 8.3.2 */
1108 /* Both TLLI Old and TLLI New are assigned; use New when
Holger Hans Peter Freyther92aa6bb2013-07-28 20:13:01 +02001109 * (re)transmitting. Accept both Old and New on Rx */
Holger Hans Peter Freytheraa93bac2013-07-31 11:20:37 +02001110 llme->old_tlli = old_tlli;
Harald Welte807a5d82010-06-01 11:53:01 +02001111 llme->tlli = new_tlli;
1112 llme->state = GPRS_LLMS_ASSIGNED;
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001113 } else if (old_tlli != TLLI_UNASSIGNED && new_tlli == TLLI_UNASSIGNED) {
Harald Welte807a5d82010-06-01 11:53:01 +02001114 /* TLLI Unassignment 8.3.3) */
1115 llme->tlli = llme->old_tlli = 0;
1116 llme->state = GPRS_LLMS_UNASSIGNED;
1117 for (i = 0; i < ARRAY_SIZE(llme->lle); i++) {
1118 struct gprs_llc_lle *l = &llme->lle[i];
1119 l->state = GPRS_LLES_UNASSIGNED;
1120 }
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +01001121 free = true;
Harald Welte807a5d82010-06-01 11:53:01 +02001122 } else
1123 return -EINVAL;
1124
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +01001125 LOGGBP(llme, DLLC, LOGL_NOTICE, "LLGM Assign post (%08x => %08x)\n",
1126 old_tlli, new_tlli);
1127
1128 if (free)
1129 llme_free(llme);
1130
Harald Welte807a5d82010-06-01 11:53:01 +02001131 return 0;
1132}
Harald Welte496aee42010-06-30 19:59:55 +02001133
Max39550252016-06-28 17:39:20 +02001134/* TLLI unassignment */
1135int gprs_llgmm_unassign(struct gprs_llc_llme *llme)
1136{
Pau Espin Pedrol404d9b82019-08-12 17:49:09 +02001137 return gprs_llgmm_assign(llme, llme->tlli, TLLI_UNASSIGNED);
Max39550252016-06-28 17:39:20 +02001138}
1139
Harald Welte0c1a3032011-10-16 18:49:05 +02001140/* Chapter 7.2.1.2 LLGMM-RESET.req */
1141int gprs_llgmm_reset(struct gprs_llc_llme *llme)
1142{
1143 struct msgb *msg = msgb_alloc_headroom(4096, 1024, "LLC_XID");
Pau Espin Pedrolb71d2c52019-11-21 16:15:52 +01001144 struct gprs_llc_lle *lle = &llme->lle[GPRS_SAPI_GMM];
Philipp4ac3aee2016-08-10 12:24:09 +02001145 uint8_t xid_bytes[1024];
Max3b6332f2017-11-01 13:28:38 +01001146 int xid_bytes_len, rc;
Philipp4ac3aee2016-08-10 12:24:09 +02001147 uint8_t *xid;
Harald Welte0c1a3032011-10-16 18:49:05 +02001148
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +01001149 LOGGBP(llme, DLLC, LOGL_NOTICE, "LLGM Reset\n");
Max3b6332f2017-11-01 13:28:38 +01001150
1151 rc = osmo_get_rand_id((uint8_t *) &llme->iov_ui, 4);
1152 if (rc < 0) {
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +01001153 LOGGBP(llme, DLLC, LOGL_ERROR,
1154 "osmo_get_rand_id() failed for LLC XID reset: %s\n",
1155 strerror(-rc));
Max3b6332f2017-11-01 13:28:38 +01001156 return rc;
Maxb997f842016-07-06 15:57:01 +02001157 }
1158
Philipp4ac3aee2016-08-10 12:24:09 +02001159 /* Generate XID message */
Harald Welteaf779d22019-04-12 16:56:04 +02001160 xid_bytes_len = gprs_llc_generate_xid_for_gmm_reset(xid_bytes, sizeof(xid_bytes),
1161 llme->iov_ui, lle);
Harald Welte7e5bb622016-09-28 08:20:58 +08001162 if (xid_bytes_len < 0)
Philipp4ac3aee2016-08-10 12:24:09 +02001163 return -EINVAL;
1164 xid = msgb_put(msg, xid_bytes_len);
1165 memcpy(xid, xid_bytes, xid_bytes_len);
Harald Welte0c1a3032011-10-16 18:49:05 +02001166
Jacob Erlbeck25ad52c2014-09-11 14:20:53 +02001167 /* Reset some of the LLC parameters. See GSM 04.64, 8.5.3.1 */
1168 lle->vu_recv = 0;
1169 lle->vu_send = 0;
1170 lle->oc_ui_send = 0;
1171 lle->oc_ui_recv = 0;
1172
Harald Welte0c1a3032011-10-16 18:49:05 +02001173 /* FIXME: Start T200, wait for XID response */
Jacob Erlbeck25ad52c2014-09-11 14:20:53 +02001174 return gprs_llc_tx_xid(lle, msg, 1);
Harald Welte0c1a3032011-10-16 18:49:05 +02001175}
1176
Maxb997f842016-07-06 15:57:01 +02001177int gprs_llgmm_reset_oldmsg(struct msgb* oldmsg, uint8_t sapi,
1178 struct gprs_llc_llme *llme)
Jacob Erlbeck78ecaf02014-09-05 14:32:36 +02001179{
1180 struct msgb *msg = msgb_alloc_headroom(4096, 1024, "LLC_XID");
Harald Welteaf779d22019-04-12 16:56:04 +02001181 struct gprs_llc_lle *lle = &llme->lle[sapi];
Philipp4ac3aee2016-08-10 12:24:09 +02001182 uint8_t xid_bytes[1024];
Max3b6332f2017-11-01 13:28:38 +01001183 int xid_bytes_len, rc;
Philipp4ac3aee2016-08-10 12:24:09 +02001184 uint8_t *xid;
Maxb997f842016-07-06 15:57:01 +02001185
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +01001186 LOGGBP(llme, DLLC, LOGL_NOTICE, "LLGM Reset (SAPI=%" PRIu8 ")\n", sapi);
Max3b6332f2017-11-01 13:28:38 +01001187
1188 rc = osmo_get_rand_id((uint8_t *) &llme->iov_ui, 4);
1189 if (rc < 0) {
Pau Espin Pedrol029a70e2019-11-21 13:58:39 +01001190 LOGGBP(llme, DLLC, LOGL_ERROR,
1191 "osmo_get_rand_id() failed for LLC XID reset: %s\n",
1192 strerror(-rc));
Max3b6332f2017-11-01 13:28:38 +01001193 return rc;
Maxb997f842016-07-06 15:57:01 +02001194 }
Jacob Erlbeck78ecaf02014-09-05 14:32:36 +02001195
Philipp4ac3aee2016-08-10 12:24:09 +02001196 /* Generate XID message */
Harald Welteaf779d22019-04-12 16:56:04 +02001197 xid_bytes_len = gprs_llc_generate_xid_for_gmm_reset(xid_bytes, sizeof(xid_bytes),
1198 llme->iov_ui, lle);
Harald Welte7e5bb622016-09-28 08:20:58 +08001199 if (xid_bytes_len < 0)
Philipp4ac3aee2016-08-10 12:24:09 +02001200 return -EINVAL;
1201 xid = msgb_put(msg, xid_bytes_len);
1202 memcpy(xid, xid_bytes, xid_bytes_len);
Jacob Erlbeck78ecaf02014-09-05 14:32:36 +02001203
1204 /* FIXME: Start T200, wait for XID response */
1205
1206 msgb_tlli(msg) = msgb_tlli(oldmsg);
1207 msgb_bvci(msg) = msgb_bvci(oldmsg);
1208 msgb_nsei(msg) = msgb_nsei(oldmsg);
1209
1210 return gprs_llc_tx_u(msg, sapi, 1, GPRS_LLC_U_XID, 1);
1211}
1212
Harald Welte496aee42010-06-30 19:59:55 +02001213int gprs_llc_init(const char *cipher_plugin_path)
1214{
1215 return gprs_cipher_load(cipher_plugin_path);
1216}