[MERGED] openbsc[master]: SGSN: fix FCS calculation for encrypted frames

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Jul 17 08:44:38 UTC 2016


Harald Welte has submitted this change and it was merged.

Change subject: SGSN: fix FCS calculation for encrypted frames
......................................................................


SGSN: fix FCS calculation for encrypted frames

Change-Id: I352bc9db0c17fff773788831c4389ec0a5a30af8
Related: OS#1582
---
M openbsc/src/gprs/gprs_llc.c
1 file changed, 10 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/openbsc/src/gprs/gprs_llc.c b/openbsc/src/gprs/gprs_llc.c
index 23fd2e3..7724ebb 100644
--- a/openbsc/src/gprs/gprs_llc.c
+++ b/openbsc/src/gprs/gprs_llc.c
@@ -357,7 +357,7 @@
 		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 @@
 	}
 
 	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 @@
 			msgb_free(msg);
 			return rc;
 		}
-
-		/* Mark frame as encrypted */
-		ctrl[1] |= 0x02;
 	}
 
 	/* Identifiers passed down: (BVCI, NSEI) */
@@ -640,6 +643,9 @@
 				       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");

-- 
To view, visit https://gerrit.osmocom.org/494
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I352bc9db0c17fff773788831c4389ec0a5a30af8
Gerrit-PatchSet: 3
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list