Skip to content

Commit a4d2552

Browse files
committed
L1CTL/L1CTL_CRYPTO_REQ: add key length and channel info
Previously, the L1CTL_CRYPTO_REQ message contained only a ciphering algorithm and actual Kc key to be used. The key length was calculated manually using the MSGB API. Let's avoid manual calculations here, as it may cause unexpected behavior if the message structure is changed. Also, let's fill the UL header with minimal information about a channel, which is going to be encrypted. Change-Id: I5fab079907c5276322d3ec2b46cab81f10c7ed09
1 parent 8b9d317 commit a4d2552

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

include/l1ctl_proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ struct l1ctl_dm_freq_req {
281281

282282
struct l1ctl_crypto_req {
283283
uint8_t algo;
284+
uint8_t key_len;
284285
uint8_t key[0];
285286
} __attribute__((packed));
286287

src/host/layer23/include/osmocom/bb/common/l1ctl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ int l1ctl_tx_data_req(struct osmocom_ms *ms, struct msgb *msg, uint8_t chan_nr,
1616
/* Transmit L1CTL_PARAM_REQ */
1717
int l1ctl_tx_param_req(struct osmocom_ms *ms, uint8_t ta, uint8_t tx_power);
1818

19-
int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t algo, uint8_t *key,
20-
uint8_t len);
19+
int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t chan_nr,
20+
uint8_t algo, uint8_t *key, uint8_t len);
2121

2222
/* Transmit L1CTL_RACH_REQ */
2323
int l1ctl_tx_rach_req(struct osmocom_ms *ms, uint8_t ra, uint16_t offset,

src/host/layer23/src/common/l1ctl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ int l1ctl_tx_param_req(struct osmocom_ms *ms, uint8_t ta, uint8_t tx_power)
427427
}
428428

429429
/* Transmit L1CTL_CRYPTO_REQ */
430-
int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t algo, uint8_t *key,
431-
uint8_t len)
430+
int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t chan_nr,
431+
uint8_t algo, uint8_t *key, uint8_t len)
432432
{
433433
struct msgb *msg;
434434
struct l1ctl_info_ul *ul;
@@ -441,7 +441,11 @@ int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t algo, uint8_t *key,
441441
DEBUGP(DL1C, "CRYPTO Req. algo=%d, len=%d\n", algo, len);
442442
ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul));
443443
req = (struct l1ctl_crypto_req *) msgb_put(msg, sizeof(*req) + len);
444+
445+
ul->chan_nr = chan_nr;
446+
req->key_len = len;
444447
req->algo = algo;
448+
445449
if (len)
446450
memcpy(req->key, key, len);
447451

src/host/layer23/src/mobile/gsm48_rr.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,11 @@ static int gsm48_rr_rx_cip_mode_cmd(struct osmocom_ms *ms, struct msgb *msg)
10051005
rr->cipher_on = sc;
10061006
rr->cipher_type = alg_id;
10071007
if (rr->cipher_on)
1008-
l1ctl_tx_crypto_req(ms, rr->cipher_type + 1, subscr->key, 8);
1008+
l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr,
1009+
rr->cipher_type + 1, subscr->key, 8);
10091010
else
1010-
l1ctl_tx_crypto_req(ms, 0, NULL, 0);
1011+
l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr,
1012+
0, NULL, 0);
10111013

10121014
/* response (using the new mode) */
10131015
return gsm48_rr_tx_cip_mode_cpl(ms, cr);
@@ -2996,7 +2998,8 @@ static int gsm48_rr_activate_channel(struct osmocom_ms *ms,
29962998
s->si5 = s->si5bis = s->si5ter = s->si6 = 0;
29972999

29983000
if (rr->cipher_on)
2999-
l1ctl_tx_crypto_req(ms, rr->cipher_type + 1, subscr->key, 8);
3001+
l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr,
3002+
rr->cipher_type + 1, subscr->key, 8);
30003003

30013004
return 0;
30023005
}
@@ -3015,7 +3018,8 @@ static int gsm48_rr_channel_after_time(struct osmocom_ms *ms,
30153018
l1ctl_tx_dm_freq_req_h0(ms, cd->arfcn, cd->tsc, fn);
30163019

30173020
if (rr->cipher_on)
3018-
l1ctl_tx_crypto_req(ms, rr->cipher_type + 1, subscr->key, 8);
3021+
l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr,
3022+
rr->cipher_type + 1, subscr->key, 8);
30193023

30203024
gsm48_rr_set_mode(ms, cd->chan_nr, cd->mode);
30213025

src/target/firmware/layer1/l23_api.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,10 @@ static void l1ctl_rx_crypto_req(struct msgb *msg)
301301
struct l1ctl_hdr *l1h = (struct l1ctl_hdr *) msg->data;
302302
struct l1ctl_info_ul *ul = (struct l1ctl_info_ul *) l1h->data;
303303
struct l1ctl_crypto_req *cr = (struct l1ctl_crypto_req *) ul->payload;
304-
uint8_t key_len = msg->len - sizeof(*l1h) - sizeof(*ul) - sizeof(*cr);
305304

306-
printd("L1CTL_CRYPTO_REQ (algo=A5/%u, len=%u)\n", cr->algo, key_len);
305+
printd("L1CTL_CRYPTO_REQ (algo=A5/%u, len=%u)\n", cr->algo, cr->key_len);
307306

308-
if (cr->algo && key_len != 8) {
307+
if (cr->algo && cr->key_len != 8) {
309308
printd("L1CTL_CRYPTO_REQ -> Invalid key\n");
310309
return;
311310
}

0 commit comments

Comments
 (0)