From patchwork Wed Aug 27 21:54:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Welte X-Patchwork-Id: 383603 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 969A71400AF for ; Thu, 28 Aug 2014 08:33:01 +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 1XMlP6-0006Wd-4u; Thu, 28 Aug 2014 00:09:20 +0200 Received: from uucp by ganesha.gnumonks.org with local-bsmtp (Exim 4.72) (envelope-from ) id 1XMlBw-0004MH-Mg; Wed, 27 Aug 2014 23:55:45 +0200 Received: from laforge by localhost.localdomain with local (Exim 4.84) (envelope-from ) id 1XMlBH-0003Ud-8D; Wed, 27 Aug 2014 23:55:03 +0200 From: Harald Welte To: openbsc@lists.osmocom.org Subject: [PATCH 04/33] l1sap: Split ph_data_req() into smaller parts Date: Wed, 27 Aug 2014 23:54:23 +0200 Message-Id: <1409176492-13269-5-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 ... in an effort to avoid introducing new/more spaghetti code Also, use offsetof() instead of pointer calculation to determine the start of GsmL1_Prim_t.u.phDataReq.msgUnitParam.u8Buffer --- src/osmo-bts-sysmo/l1_if.c | 72 ++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c index 54e4761..542e3ce 100644 --- a/src/osmo-bts-sysmo/l1_if.c +++ b/src/osmo-bts-sysmo/l1_if.c @@ -1,6 +1,6 @@ /* Interface handler for Sysmocom L1 */ -/* (C) 2011 by Harald Welte +/* (C) 2011-2014 by Harald Welte * (C) 2014 by Holger Hans Peter Freyther * * All Rights Reserved @@ -416,6 +416,49 @@ static const uint8_t fill_frame[GSM_MACBLOCK_LEN] = { 0x2B, 0x2B, 0x2B }; +/* fill PH-DATA.req from l1sap primitive */ +static GsmL1_PhDataReq_t * +data_req_from_l1sap(GsmL1_Prim_t *l1p, struct femtol1_hdl *fl1, + uint8_t tn, uint32_t fn, uint8_t sapi, uint8_t sub_ch, + uint8_t block_nr, uint8_t len) +{ + GsmL1_PhDataReq_t *data_req = &l1p->u.phDataReq; + + l1p->id = GsmL1_PrimId_PhDataReq; + + /* copy fields from PH-RSS.ind */ + data_req->hLayer1 = fl1->hLayer1; + data_req->u8Tn = tn; + data_req->u32Fn = fn; + data_req->sapi = sapi; + data_req->subCh = sub_ch; + data_req->u8BlockNbr = block_nr; + + data_req->msgUnitParam.u8Size = len; + + return data_req; +} + +/* fill PH-EMPTY_FRAME.req from l1sap primitive */ +static GsmL1_PhEmptyFrameReq_t * +empty_req_from_l1sap(GsmL1_Prim_t *l1p, struct femtol1_hdl *fl1, + uint8_t tn, uint32_t fn, uint8_t sapi, + uint8_t subch, uint8_t block_nr) +{ + GsmL1_PhEmptyFrameReq_t *empty_req = &l1p->u.phEmptyFrameReq; + + l1p->id = GsmL1_PrimId_PhEmptyFrameReq; + + empty_req->hLayer1 = fl1->hLayer1; + empty_req->u8Tn = tn; + empty_req->u32Fn = fn; + empty_req->sapi = sapi; + empty_req->subCh = subch; + empty_req->u8BlockNbr = block_nr; + + return empty_req; +} + static int ph_data_req(struct gsm_bts_trx *trx, struct msgb *msg, struct osmo_phsap_prim *l1sap) { @@ -453,15 +496,11 @@ static int ph_data_req(struct gsm_bts_trx *trx, struct msgb *msg, /* convert l1sap message to GsmL1 primitive, keep payload */ if (len) { /* data request */ - GsmL1_PhDataReq_t *data_req; - GsmL1_MsgUnitParam_t *msu_param; - uint8_t *temp; /* wrap zeroed l1p structure arrount payload * this must be done in three steps, since the actual * payload is not at the end but inside the l1p structure. */ - temp = l1p->u.phDataReq.msgUnitParam.u8Buffer; - msgb_push(msg, temp - (uint8_t *)l1p); + msgb_push(msg, offsetof(GsmL1_Prim_t, u.phDataReq.msgUnitParam.u8Buffer)); memset(msg->data, 0, msg->len); msgb_put(msg, len); memset(msg->tail, 0, sizeof(*l1p) - msg->len); @@ -469,19 +508,9 @@ static int ph_data_req(struct gsm_bts_trx *trx, struct msgb *msg, msg->l1h = msg->data; l1p = msgb_l1prim(msg); - l1p->id = GsmL1_PrimId_PhDataReq; - data_req = &l1p->u.phDataReq; - data_req->hLayer1 = fl1->hLayer1; - data_req->u8Tn = u8Tn; - data_req->u32Fn = u32Fn; - data_req->sapi = sapi; - data_req->subCh = subCh; - data_req->u8BlockNbr = u8BlockNbr; - msu_param = &data_req->msgUnitParam; - msu_param->u8Size = len; + data_req_from_l1sap(l1p, fl1, u8Tn, u32Fn, sapi, subCh, u8BlockNbr, len); } else { /* empty frame */ - GsmL1_PhEmptyFrameReq_t *empty_req; /* put l1p structure */ msgb_put(msg, sizeof(*l1p)); @@ -489,14 +518,7 @@ static int ph_data_req(struct gsm_bts_trx *trx, struct msgb *msg, msg->l1h = msg->data; l1p = msgb_l1prim(msg); - l1p->id = GsmL1_PrimId_PhEmptyFrameReq; - empty_req = &l1p->u.phEmptyFrameReq; - empty_req->hLayer1 = fl1->hLayer1; - empty_req->u8Tn = u8Tn; - empty_req->u32Fn = u32Fn; - empty_req->sapi = sapi; - empty_req->subCh = subCh; - empty_req->u8BlockNbr = u8BlockNbr; + empty_req_from_l1sap(l1p, fl1, u8Tn, u32Fn, sapi, subCh, u8BlockNbr); } /* send message to DSP's queue */