From f1d33447814391967186222b64780a4abd150453 Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Sat, 23 Apr 2011 15:34:11 +0200 Subject: gsm/a5: Add a A5 1&2 implementation It's always useful to have around Signed-off-by: Sylvain Munaut --- include/osmocom/gsm/Makefile.am | 2 +- include/osmocom/gsm/a5.h | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 include/osmocom/gsm/a5.h (limited to 'include') diff --git a/include/osmocom/gsm/Makefile.am b/include/osmocom/gsm/Makefile.am index 8685fc9a..a39d2d04 100644 --- a/include/osmocom/gsm/Makefile.am +++ b/include/osmocom/gsm/Makefile.am @@ -1,4 +1,4 @@ -osmogsm_HEADERS = comp128.h gsm0808.h gsm48_ie.h mncc.h rxlev_stat.h \ +osmogsm_HEADERS = a5.h comp128.h gsm0808.h gsm48_ie.h mncc.h rxlev_stat.h \ gsm0480.h gsm48.h gsm_utils.h rsl.h tlv.h SUBDIRS = protocol diff --git a/include/osmocom/gsm/a5.h b/include/osmocom/gsm/a5.h new file mode 100644 index 00000000..2c630e5f --- /dev/null +++ b/include/osmocom/gsm/a5.h @@ -0,0 +1,49 @@ +/* + * a5.h + * + * Copyright (C) 2011 Sylvain Munaut + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __OSMO_A5_H__ +#define __OSMO_A5_H__ + +#include + +#include + +static inline uint32_t +osmo_a5_fn_count(uint32_t fn) +{ + int t1 = fn / (26 * 51); + int t2 = fn % 26; + int t3 = fn % 51; + return (t1 << 11) | (t3 << 5) | t2; +} + + /* Notes: + * - key must be 8 bytes long (or NULL for A5/0) + * - the dl and ul pointer must be either NULL or 114 bits long + * - fn is the _real_ GSM frame number. + * (converted internally to fn_count) + */ +void osmo_a5(int n, uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); +void osmo_a5_1(uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); +void osmo_a5_2(uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); + +#endif /* __OSMO_A5_H__ */ -- cgit v1.2.3