Review at https://gerrit.osmocom.org/6810
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: I1813a188e755141241273479b17896415abcc3f1 --- M include/l1ctl_proto.h M src/host/layer23/include/osmocom/bb/common/l1ctl.h M src/host/layer23/src/common/l1ctl.c M src/host/layer23/src/mobile/gsm48_rr.c M src/target/firmware/layer1/l23_api.c 5 files changed, 19 insertions(+), 11 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/10/6810/1 diff --git a/include/l1ctl_proto.h b/include/l1ctl_proto.h index 37d3d87..87e1fc3 100644 --- a/include/l1ctl_proto.h +++ b/include/l1ctl_proto.h @@ -280,6 +280,7 @@ struct l1ctl_crypto_req { uint8_t algo; + uint8_t key_len; uint8_t key[0]; } __attribute__((packed)); diff --git a/src/host/layer23/include/osmocom/bb/common/l1ctl.h b/src/host/layer23/include/osmocom/bb/common/l1ctl.h index 3534589..824b1b0 100644 --- a/src/host/layer23/include/osmocom/bb/common/l1ctl.h +++ b/src/host/layer23/include/osmocom/bb/common/l1ctl.h @@ -16,8 +16,8 @@ /* Transmit L1CTL_PARAM_REQ */ int l1ctl_tx_param_req(struct osmocom_ms *ms, uint8_t ta, uint8_t tx_power); -int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t algo, uint8_t *key, - uint8_t len); +int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t chan_nr, + uint8_t algo, uint8_t *key, uint8_t len); /* Transmit L1CTL_RACH_REQ */ int l1ctl_tx_rach_req(struct osmocom_ms *ms, uint8_t ra, uint16_t offset, diff --git a/src/host/layer23/src/common/l1ctl.c b/src/host/layer23/src/common/l1ctl.c index 3e642df..f4c214d 100644 --- a/src/host/layer23/src/common/l1ctl.c +++ b/src/host/layer23/src/common/l1ctl.c @@ -408,8 +408,8 @@ } /* Transmit L1CTL_CRYPTO_REQ */ -int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t algo, uint8_t *key, - uint8_t len) +int l1ctl_tx_crypto_req(struct osmocom_ms *ms, uint8_t chan_nr, + uint8_t algo, uint8_t *key, uint8_t len) { struct msgb *msg; struct l1ctl_info_ul *ul; @@ -422,7 +422,11 @@ DEBUGP(DL1C, "CRYPTO Req. algo=%d, len=%d\n", algo, len); ul = (struct l1ctl_info_ul *) msgb_put(msg, sizeof(*ul)); req = (struct l1ctl_crypto_req *) msgb_put(msg, sizeof(*req) + len); + + ul->chan_nr = chan_nr; + req->key_len = len; req->algo = algo; + if (len) memcpy(req->key, key, len); diff --git a/src/host/layer23/src/mobile/gsm48_rr.c b/src/host/layer23/src/mobile/gsm48_rr.c index ac27214..729170a 100644 --- a/src/host/layer23/src/mobile/gsm48_rr.c +++ b/src/host/layer23/src/mobile/gsm48_rr.c @@ -1005,9 +1005,11 @@ rr->cipher_on = sc; rr->cipher_type = alg_id; if (rr->cipher_on) - l1ctl_tx_crypto_req(ms, rr->cipher_type + 1, subscr->key, 8); + l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr, + rr->cipher_type + 1, subscr->key, 8); else - l1ctl_tx_crypto_req(ms, 0, NULL, 0); + l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr, + 0, NULL, 0); /* response (using the new mode) */ return gsm48_rr_tx_cip_mode_cpl(ms, cr); @@ -3001,7 +3003,8 @@ s->si5 = s->si5bis = s->si5ter = s->si6 = 0; if (rr->cipher_on) - l1ctl_tx_crypto_req(ms, rr->cipher_type + 1, subscr->key, 8); + l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr, + rr->cipher_type + 1, subscr->key, 8); return 0; } @@ -3020,7 +3023,8 @@ l1ctl_tx_dm_freq_req_h0(ms, cd->arfcn, cd->tsc, fn); if (rr->cipher_on) - l1ctl_tx_crypto_req(ms, rr->cipher_type + 1, subscr->key, 8); + l1ctl_tx_crypto_req(ms, rr->cd_now.chan_nr, + rr->cipher_type + 1, subscr->key, 8); gsm48_rr_set_mode(ms, cd->chan_nr, cd->mode); diff --git a/src/target/firmware/layer1/l23_api.c b/src/target/firmware/layer1/l23_api.c index 311ca6a..e53b0c8 100644 --- a/src/target/firmware/layer1/l23_api.c +++ b/src/target/firmware/layer1/l23_api.c @@ -301,11 +301,10 @@ struct l1ctl_hdr *l1h = (struct l1ctl_hdr *) msg->data; struct l1ctl_info_ul *ul = (struct l1ctl_info_ul *) l1h->data; struct l1ctl_crypto_req *cr = (struct l1ctl_crypto_req *) ul->payload; - uint8_t key_len = msg->len - sizeof(*l1h) - sizeof(*ul) - sizeof(*cr); - printd("L1CTL_CRYPTO_REQ (algo=A5/%u, len=%u)\n", cr->algo, key_len); + printd("L1CTL_CRYPTO_REQ (algo=A5/%u, len=%u)\n", cr->algo, cr->key_len); - if (cr->algo && key_len != 8) { + if (cr->algo && cr->key_len != 8) { printd("L1CTL_CRYPTO_REQ -> Invalid key\n"); return; } -- To view, visit https://gerrit.osmocom.org/6810 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1813a188e755141241273479b17896415abcc3f1 Gerrit-PatchSet: 1 Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>