From patchwork Wed Dec 9 17:20:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruben Undheim X-Patchwork-Id: 554723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (unknown [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 6E3541402CD for ; Thu, 10 Dec 2015 04:21:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=KbDlRKKd; dkim-atps=neutral Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 0AFC4AC76; Wed, 9 Dec 2015 17:21:00 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail-io0-x233.google.com (mail-io0-x233.google.com [IPv6:2607:f8b0:4001:c06::233]) by lists.osmocom.org (Postfix) with ESMTP id A752BAC6F for ; Wed, 9 Dec 2015 17:20:59 +0000 (UTC) Received: by iouu10 with SMTP id u10so68053157iou.0 for ; Wed, 09 Dec 2015 09:20:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=dctxWH4wsX0Psx1+t6eJ9bFLWJMs8eFVI1DTx7OxBpU=; b=KbDlRKKdE4mnZLYsSu57+5x4priektWmYSN/+2uuY4UvUcekBye/eQI/z201MhA3nb f7QFAvrST5Ly43rqSTZhAJ1XSZRzBLNUq4xpYBEyc0XY1yecULgUxxsMTnA43C4kRGYp Q3G4kGzuMIAcT6ORr33Is4Gg26wzghw4JVKrfnEkJmGjgXg/e5va6oyoRusSo5BPfaeS AZ0A4qwwz6IJvQHKMdpTtLipQ9gW8CcyB1rqs+Z8DG8ijI4mTE2HxcMfYNdyT4SyPs5o unnwZbhChRUxvD4MorHro16h0/5GA0OavznvyYu+qw8mr409R9Giwn33P+NyghyaWXNj BwZQ== MIME-Version: 1.0 X-Received: by 10.107.166.82 with SMTP id p79mr6352134ioe.187.1449681658339; Wed, 09 Dec 2015 09:20:58 -0800 (PST) Received: by 10.36.193.198 with HTTP; Wed, 9 Dec 2015 09:20:58 -0800 (PST) In-Reply-To: References: <20151206211538.GK17730@nataraja> Date: Wed, 9 Dec 2015 18:20:58 +0100 Message-ID: Subject: Re: The test suite for libosmocore fails on big-endian architectures From: Ruben Undheim To: Harald Welte X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openbsc@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" Hi, In the end, I ended up with the following patch that works: Note that the order of the fields is a bit different than your proposal. I also, interestingly enough, found this: http://lists.osmocom.org/pipermail/baseband-devel/2015-February/000021.html It's from Februrary, and already a suggestion for a patch for this problem. I don't think however that patch will work with other big-endian architectures. Cheers, Ruben 2015-12-07 22:16 GMT+01:00 Ruben Undheim : > Hi, > > Thanks! > > Apparently it doesn't work correctly, but I'm now trying with: > #if OSMO_IS_LITTLE_ENDIAN == 1 > > instead, and I have big hopes. > > (OSMO_IS_LITTLE_ENDIAN is always defined, 1 for low-endian archs and 0 > for big-endian archs.) > > Cheers, > Ruben > > 2015-12-06 22:15 GMT+01:00 Harald Welte : >> Hi Ruben, >> >> On Sun, Dec 06, 2015 at 04:53:09PM +0100, Ruben Undheim wrote: >>> While building the package for Debian, apparently there is a problem >>> related to big-endian architectures. >> >> While I still own several PPC machines, I haven't booted any of them in >> years, and don't have a build setup ready. Please try the patch >> below and report back if it works. If yes, we can merge it. >> >> From 51ae645e220556bbeabce3ac57304639328e2164 Mon Sep 17 00:00:00 2001 >> From: Harald Welte >> Date: Sun, 6 Dec 2015 22:12:43 +0100 >> Subject: [PATCH] untested fix for gsm_03_41.h and big-endian machines >> >> Our gsm_03_41 structs use bit-fields, but don't do the usual >> little/big-endian jumping. >> --- >> include/osmocom/gsm/protocol/gsm_03_41.h | 27 +++++++++++++++++++++++++++ >> 1 file changed, 27 insertions(+) >> >> diff --git a/include/osmocom/gsm/protocol/gsm_03_41.h b/include/osmocom/gsm/protocol/gsm_03_41.h >> index 0ece6cc..f007cc1 100644 >> --- a/include/osmocom/gsm/protocol/gsm_03_41.h >> +++ b/include/osmocom/gsm/protocol/gsm_03_41.h >> @@ -2,6 +2,7 @@ >> >> #include >> >> +#include >> #include >> >> /* GSM TS 03.41 definitions also TS 23.041*/ >> @@ -13,19 +14,36 @@ >> /* Chapter 9.3.2 */ >> struct gsm341_ms_message { >> struct { >> +#ifdef OSMO_IS_LITTLE_ENDIAN >> uint8_t code_hi:6; >> uint8_t gs:2; >> uint8_t update:4; >> uint8_t code_lo:4; >> +#else >> + uint8_t code_lo:4; >> + uint8_t update:4; >> + uint8_t gs:2; >> + uint8_t code_hi:6; >> +#endif >> } serial; >> uint16_t msg_id; >> struct { >> +#ifdef OSMO_IS_LITTLE_ENDIAN >> uint8_t language:4; >> uint8_t group:4; >> +#else >> + uint8_t group:4; >> + uint8_t language:4; >> +#endif >> } dcs; >> struct { >> +#ifdef OSMO_IS_LITTLE_ENDIAN >> uint8_t total:4; >> uint8_t current:4; >> +#else >> + uint8_t current:4; >> + uint8_t total:4; >> +#endif >> } page; >> uint8_t data[0]; >> } __attribute__((packed)); >> @@ -33,12 +51,21 @@ struct gsm341_ms_message { >> /* Chapter 9.4.1.3 */ >> struct gsm341_etws_message { >> struct { >> +#ifdef OSMO_IS_LITTLE_ENDIAN >> uint8_t code_hi:4; >> uint8_t popup:1; >> uint8_t alert:1; >> uint8_t gs:2; >> uint8_t update:4; >> uint8_t code_lo:4; >> +#else >> + uint8_t code_lo:4; >> + uint8_t update:4; >> + uint8_t gs:2; >> + uint8_t alert:1; >> + uint8_t popup:1; >> + uint8_t code_hi:4; >> +#endif >> } serial; >> uint16_t msg_id; >> uint16_t warning_type; >> -- >> 2.6.2 >> >> -- >> - Harald Welte http://laforge.gnumonks.org/ >> ============================================================================ >> "Privacy in residential applications is a desirable marketing option." >> (ETSI EN 300 175-7 Ch. A6) diff --git a/include/osmocom/gsm/protocol/gsm_03_41.h b/include/osmocom/gsm/protocol/gsm_03_41.h index 0ece6cc..40051cd 100644 --- a/include/osmocom/gsm/protocol/gsm_03_41.h +++ b/include/osmocom/gsm/protocol/gsm_03_41.h @@ -2,8 +2,13 @@ #include +#include #include +#ifndef OSMO_IS_LITTLE_ENDIAN + #define OSMO_IS_LITTLE_ENDIAN 0 +#endif + /* GSM TS 03.41 definitions also TS 23.041*/ #define GSM341_MAX_PAYLOAD (GSM412_MSG_LEN-sizeof(struct gsm341_ms_message)) @@ -13,19 +18,36 @@ /* Chapter 9.3.2 */ struct gsm341_ms_message { struct { +#if OSMO_IS_LITTLE_ENDIAN == 1 uint8_t code_hi:6; uint8_t gs:2; uint8_t update:4; uint8_t code_lo:4; +#else + uint8_t gs:2; + uint8_t code_hi:6; + uint8_t code_lo:4; + uint8_t update:4; +#endif } serial; uint16_t msg_id; struct { +#if OSMO_IS_LITTLE_ENDIAN == 1 uint8_t language:4; uint8_t group:4; +#else + uint8_t group:4; + uint8_t language:4; +#endif } dcs; struct { +#if OSMO_IS_LITTLE_ENDIAN == 1 uint8_t total:4; uint8_t current:4; +#else + uint8_t current:4; + uint8_t total:4; +#endif } page; uint8_t data[0]; } __attribute__((packed)); @@ -33,12 +55,21 @@ struct gsm341_ms_message { /* Chapter 9.4.1.3 */ struct gsm341_etws_message { struct { +#if OSMO_IS_LITTLE_ENDIAN == 1 uint8_t code_hi:4; uint8_t popup:1; uint8_t alert:1; uint8_t gs:2; uint8_t update:4; uint8_t code_lo:4; +#else + uint8_t gs:2; + uint8_t alert:1; + uint8_t popup:1; + uint8_t code_hi:4; + uint8_t code_lo:4; + uint8_t update:4; +#endif } serial; uint16_t msg_id; uint16_t warning_type;