Signed-off-by: Max Suraev <Max.Suraev(a)fairwaves.co>
---
include/osmocom/gsm/gsm_utils.h | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/include/osmocom/gsm/gsm_utils.h b/include/osmocom/gsm/gsm_utils.h
index 6eab7ac..cf174e2 100644
--- a/include/osmocom/gsm/gsm_utils.h
+++ b/include/osmocom/gsm/gsm_utils.h
@@ -117,17 +117,41 @@ int rxlev2dbm(uint8_t rxlev);
uint8_t dbm2rxlev(int dbm);
/* According to GSM 04.08 Chapter 10.5.1.6 */
-static inline int ms_cm2_a5n_support(uint8_t *cm2, int n) {
+static inline int ms_cm2_a5n_support(uint8_t *cm2, unsigned n) {
switch (n) {
case 0: return 1;
case 1: return (cm2[0] & (1<<3)) ? 0 : 1;
case 2: return (cm2[2] & (1<<0)) ? 1 : 0;
case 3: return (cm2[2] & (1<<1)) ? 1 : 0;
default:
- return 0;
+ return (n > 7) ? 0 : -1;
}
}
+/* According to GSM 04.08 Chapter 10.5.1.7 */
+static inline int ms_cm3_a5n_support(uint8_t *cm3, unsigned n) {
+ switch (n) {
+ case 4: return (cm3[0] & (1<<0)) ? 1 : 0;
+ case 5: return (cm3[0] & (1<<1)) ? 1 : 0;
+ case 6: return (cm3[0] & (1<<2)) ? 1 : 0;
+ case 7: return (cm3[0] & (1<<3)) ? 1 : 0;
+ default:
+ return (n > 7) ? 0 : -1;
+ }
+}
+
+/*! \brief Check whether MS supports given cipher
+ * \param[in] cm Classmark data transmitted by MS, cannot be NULL
+ * \param[in] n Cipher number - A5/n
+ * \returns 1 if supported, 0 if unsupported, -1 on failures
+ *
+ * Implementation based on specifications from GSM 04.08
+ * parts 10.5.1.6 and 10.5.1.7.
+ */
+static inline int ms_a5n_support(uint8_t *cm, unsigned n) {
+ return ((n < 4) ? ms_cm2_a5n_support(cm, n) : ms_cm3_a5n_support(cm, n));
+}
+
/* According to GSM 04.08 Chapter 10.5.2.29 */
static inline int rach_max_trans_val2raw(int val) { return (val >> 1) & 3; }
static inline int rach_max_trans_raw2val(int raw) {
--
1.9.1