From patchwork Wed Aug 27 21:54:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Welte X-Patchwork-Id: 383596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AB37E14010F for ; Thu, 28 Aug 2014 08:16:05 +1000 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1XMlVV-0007Jw-02; Thu, 28 Aug 2014 00:15:57 +0200 Received: from uucp by ganesha.gnumonks.org with local-bsmtp (Exim 4.72) (envelope-from ) id 1XMlCE-0004Nz-HN; Wed, 27 Aug 2014 23:56:03 +0200 Received: from laforge by localhost.localdomain with local (Exim 4.84) (envelope-from ) id 1XMlBI-0003X7-6z; Wed, 27 Aug 2014 23:55:04 +0200 From: Harald Welte To: openbsc@lists.osmocom.org Subject: [PATCH 26/33] l1sap: Port code to new ciphering handling Date: Wed, 27 Aug 2014 23:54:45 +0200 Message-Id: <1409176492-13269-27-git-send-email-laforge@gnumonks.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1409176492-13269-1-git-send-email-laforge@gnumonks.org> References: <1409176492-13269-1-git-send-email-laforge@gnumonks.org> Cc: Harald Welte X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openbsc-bounces@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org ... introduced in 2cc37035d73191b71b9ba9c0d559a0da6a5f35e5 --- include/osmo-bts/l1sap.h | 2 ++ src/common/l1sap.c | 51 +++++++++++++++++++++++++++++++++--------- src/osmo-bts-sysmo/l1_if.c | 32 -------------------------- src/osmo-bts-sysmo/l1_if.h | 3 --- tests/sysmobts/sysmobts_test.c | 5 +++-- 5 files changed, 46 insertions(+), 47 deletions(-) diff --git a/include/osmo-bts/l1sap.h b/include/osmo-bts/l1sap.h index dee430f..8165c81 100644 --- a/include/osmo-bts/l1sap.h +++ b/include/osmo-bts/l1sap.h @@ -68,4 +68,6 @@ extern uint8_t gsmtap_sapi_acch; #define msgb_l1sap_prim(msg) ((struct osmo_phsap_prim *)(msg)->l1h) +void bts_check_for_first_ciphrd(struct gsm_lchan *lchan, + uint8_t *data, int len, uint8_t chan_nr); #endif /* L1SAP_H */ diff --git a/src/common/l1sap.c b/src/common/l1sap.c index 14dbde9..3f942e6 100644 --- a/src/common/l1sap.c +++ b/src/common/l1sap.c @@ -481,6 +481,46 @@ static void radio_link_timeout(struct gsm_lchan *lchan, int bad_frame) } } +static inline void check_for_first_ciphrd(struct gsm_lchan *lchan, + uint8_t *data, int len, + uint8_t chan_nr) +{ + uint8_t n_s; + + /* if this is the first valid message after enabling Rx + * decryption, we have to enable Tx encryption */ + if (lchan->ciph_state != LCHAN_CIPH_RX_CONF) { + printf("ciph_State\n"); + return; + } + + /* HACK: check if it's an I frame, in order to + * ignore some still buffered/queued UI frames received + * before decryption was enabled */ + if (data[0] != 0x01) + return; + + if ((data[1] & 0x01) != 0) + return; + + n_s = data[1] >> 5; + if (lchan->ciph_ns != n_s) + return; + + lchan->ciph_state = LCHAN_CIPH_TXRX_REQ; + + /* this check is only introduced to make the test work :/ */ + if (lchan->ts && lchan->ts->trx) + l1sap_tx_ciph_req(lchan->ts->trx, chan_nr, 1, 0); +} + +/* public helper for the test */ +void bts_check_for_first_ciphrd(struct gsm_lchan *lchan, + uint8_t *data, int len, uint8_t chan_nr) +{ + return check_for_first_ciphrd(lchan, data, len, chan_nr); +} + /* DATA received from bts model */ static int l1sap_ph_data_ind(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap, struct ph_data_param *data_ind) @@ -557,16 +597,7 @@ static int l1sap_ph_data_ind(struct gsm_bts_trx *trx, } else le = &lchan->lapdm_ch.lapdm_dcch; - /* if this is the first valid message after enabling Rx - * decryption, we have to enable Tx encryption */ - if (lchan->ciph_state == LCHAN_CIPH_RX_CONF) { - /* HACK: check if it's an I frame, in order to - * ignore some still buffered/queued UI frames received - * before decryption was enabled */ - if (data[0] == 0x01 && (data[1] & 0x01) == 0) { - l1sap_tx_ciph_req(trx, chan_nr, 1, 0); - } - } + check_for_first_ciphrd(lchan, data, len, chan_nr); /* SDCCH, SACCH and FACCH all go to LAPDm */ msgb_pull(msg, (msg->l2h - msg->data)); diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c index b62a2a3..14efc2c 100644 --- a/src/osmo-bts-sysmo/l1_if.c +++ b/src/osmo-bts-sysmo/l1_if.c @@ -356,31 +356,6 @@ static int check_for_ciph_cmd(struct femtol1_hdl *fl1h, return 1; } -static inline void check_for_first_ciphrd(struct femtol1_hdl *fl1h, - GsmL1_MsgUnitParam_t *msgUnitParam, - struct gsm_lchan *lchan) -{ - uint8_t n_s; - - /* if this is the first valid message after enabling Rx - * decryption, we have to enable Tx encryption */ - if (lchan->ciph_state != LCHAN_CIPH_RX_CONF) - return; - - /* HACK: check if it's an I frame, in order to - * ignore some still buffered/queued UI frames received - * before decryption was enabled */ - if (msgUnitParam->u8Buffer[0] != 0x01) - return; - if ((msgUnitParam->u8Buffer[1] & 0x01) != 0) - return; - n_s = msgUnitParam->u8Buffer[1] >> 5; - if (lchan->ciph_ns != n_s) - return; - lchan->ciph_state = LCHAN_CIPH_TXRX_REQ; - l1if_set_ciphering(fl1h, lchan, 1); -} - /* public helpers for the test */ int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h, struct msgb *msg, struct gsm_lchan *lchan) @@ -388,13 +363,6 @@ int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h, return check_for_ciph_cmd(fl1h, msg, lchan); } -void bts_check_for_first_ciphrd(struct femtol1_hdl *fl1h, - GsmL1_MsgUnitParam_t *msgUnitParam, - struct gsm_lchan *lchan) -{ - return check_for_first_ciphrd(fl1h, msgUnitParam, lchan); -} - static const uint8_t fill_frame[GSM_MACBLOCK_LEN] = { 0x03, 0x03, 0x01, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, 0x2B, diff --git a/src/osmo-bts-sysmo/l1_if.h b/src/osmo-bts-sysmo/l1_if.h index 6f58e95..a425776 100644 --- a/src/osmo-bts-sysmo/l1_if.h +++ b/src/osmo-bts-sysmo/l1_if.h @@ -138,7 +138,4 @@ int l1if_rf_clock_info_correct(struct femtol1_hdl *fl1h); /* public helpers for test */ int bts_check_for_ciph_cmd(struct femtol1_hdl *fl1h, struct msgb *msg, struct gsm_lchan *lchan); -void bts_check_for_first_ciphrd(struct femtol1_hdl *fl1h, - GsmL1_MsgUnitParam_t *msgUnitParam, - struct gsm_lchan *lchan); #endif /* _FEMTO_L1_H */ diff --git a/tests/sysmobts/sysmobts_test.c b/tests/sysmobts/sysmobts_test.c index acbc09c..d5035bd 100644 --- a/tests/sysmobts/sysmobts_test.c +++ b/tests/sysmobts/sysmobts_test.c @@ -18,6 +18,7 @@ */ #include +#include #include "femtobts.h" #include "l1_if.h" @@ -169,13 +170,13 @@ static void test_sysmobts_cipher(void) /* Handle message sent before ciphering was received */ memcpy(&unit.u8Buffer[0], too_early_classmark, ARRAY_SIZE(too_early_classmark)); unit.u8Size = ARRAY_SIZE(too_early_classmark); - bts_check_for_first_ciphrd(&fl1h, &unit, &lchan); + bts_check_for_first_ciphrd(&lchan, unit.u8Buffer, unit.u8Size, 0); OSMO_ASSERT(lchan.ciph_state == LCHAN_CIPH_RX_CONF); /* Now send the first ciphered message */ memcpy(&unit.u8Buffer[0], first_ciphered_cipher_cmpl, ARRAY_SIZE(first_ciphered_cipher_cmpl)); unit.u8Size = ARRAY_SIZE(first_ciphered_cipher_cmpl); - bts_check_for_first_ciphrd(&fl1h, &unit, &lchan); + bts_check_for_first_ciphrd(&lchan, unit.u8Buffer, unit.u8Size, 0); OSMO_ASSERT(lchan.ciph_state == LCHAN_CIPH_TXRX_REQ); }