diff options
author | Dieter Spaar <spaar@mirider.augusta.de> | 2016-07-11 12:48:07 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2016-07-17 08:44:38 +0000 |
commit | b572d7c45eaa65d7b36ab339022e560f2e797098 (patch) | |
tree | 78cb25e63e73d909482423f5d31870cc17e910ae /openbsc/src | |
parent | 9ddd8e6267a744caa0f206eeccb28b413fc987d5 (diff) |
SGSN: fix FCS calculation for encrypted frames
Change-Id: I352bc9db0c17fff773788831c4389ec0a5a30af8
Related: OS#1582
Diffstat (limited to 'openbsc/src')
-rw-r--r-- | openbsc/src/gprs/gprs_llc.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/openbsc/src/gprs/gprs_llc.c b/openbsc/src/gprs/gprs_llc.c index 23fd2e369..7724ebb5b 100644 --- a/openbsc/src/gprs/gprs_llc.c +++ b/openbsc/src/gprs/gprs_llc.c @@ -357,7 +357,7 @@ static int apply_gea(struct gprs_llc_lle *lle, uint16_t crypt_len, uint16_t nu, return -EINVAL; /* Compute the 'Input' Paraemeter */ - uint32_t iv = gprs_cipher_gen_input_ui(lle->llme->iov_ui, sapi, + uint32_t fcs_calc, iv = gprs_cipher_gen_input_ui(lle->llme->iov_ui, sapi, nu, oc); /* Compute gamma that we need to XOR with the data */ int r = gprs_cipher_run(cipher_out, crypt_len, lle->llme->algo, @@ -371,6 +371,12 @@ static int apply_gea(struct gprs_llc_lle *lle, uint16_t crypt_len, uint16_t nu, } if (fcs) { + /* Mark frame as encrypted and update FCS */ + data[2] |= 0x02; + fcs_calc = gprs_llc_fcs(data, fcs - data); + fcs[0] = fcs_calc & 0xff; + fcs[1] = (fcs_calc >> 8) & 0xff; + fcs[2] = (fcs_calc >> 16) & 0xff; data += 3; } @@ -452,9 +458,6 @@ int gprs_llc_tx_ui(struct msgb *msg, uint8_t sapi, int command, msgb_free(msg); return rc; } - - /* Mark frame as encrypted */ - ctrl[1] |= 0x02; } /* Identifiers passed down: (BVCI, NSEI) */ @@ -640,6 +643,9 @@ int gprs_llc_rcvmsg(struct msgb *msg, struct tlv_parsed *tv) llhp.data); if (rc < 0) return rc; + llhp.fcs = *(llhp.data + llhp.data_len); + llhp.fcs |= *(llhp.data + llhp.data_len + 1) << 8; + llhp.fcs |= *(llhp.data + llhp.data_len + 2) << 16; } else { LOGP(DLLC, LOGL_NOTICE, "encrypted frame for LLC that " "has no KC/Algo! Dropping.\n"); |