endian: Use the new endian macros for portability

Use the new macros to deal with little/big endian. Im a bit
worried to make this change due the little test coverage in
this module but in case of a typo the elements would not be
defined.
This commit is contained in:
Holger Hans Peter Freyther 2015-03-22 09:37:17 +01:00
parent d69c1ca8fa
commit 86115434f1
6 changed files with 17 additions and 13 deletions

View File

@ -32,8 +32,6 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
CFLAGS="$saved_CFLAGS"
AC_SUBST(SYMBOL_VISIBILITY)
AC_CHECK_HEADER([endian.h], [], [AC_MSG_ERROR([endian.h not found!]) ])
dnl Generate the output
AM_CONFIG_HEADER(config.h)

View File

@ -9,6 +9,7 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
#include <osmocom/core/endian.h>
#include <osmocom/netif/rs232.h>
@ -110,13 +111,13 @@ static void ubx_checksum(struct msgb *msg, uint8_t *ck)
}
}
# if __BYTE_ORDER == __LITTLE_ENDIAN
# if OSMO_IS_LITTLE_ENDIAN
# define utohl(x) (x)
# define utohs(x) (x)
# define htoul(x) (x)
# define htous(x) (x)
# else
# if __BYTE_ORDER == __BIG_ENDIAN
# if OSMO_IS_BIG_ENDIAN
# define utohl(x) __bswap_32 (x)
# define utohs(x) __bswap_16 (x)
# define htoul(x) __bswap_32 (x)

View File

@ -1,6 +1,8 @@
#ifndef _OSMO_AMR_H_
#define _OSMO_AMR_H_
#include <osmocom/core/endian.h>
/* As defined by RFC3267: Adaptive Multi-Rate (AMR) */
/*
@ -41,7 +43,7 @@
*/
struct amr_hdr {
#if __BYTE_ORDER == __BIG_ENDIAN
#if OSMO_IS_BIG_ENDIAN
/* Payload Header */
uint8_t cmr:4, /* Codec Mode Request */
pad1:4;
@ -50,7 +52,7 @@ struct amr_hdr {
ft:4, /* coding mode */
q:1, /* OK (not damaged) at origin? */
pad2:2;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#elif OSMO_IS_LITTLE_ENDIAN
/* Payload Header */
uint8_t pad1:4,
cmr:4;

View File

@ -1,6 +1,8 @@
#ifndef _OSMUX_H_
#define _OSMUX_H_
#include <osmocom/core/endian.h>
/* OSmux header:
*
* ft (3 bits): 0=signalling, 1=voice
@ -17,12 +19,12 @@
#define OSMUX_FT_VOICE_AMR 1
struct osmux_hdr {
#if __BYTE_ORDER == __BIG_ENDIAN
#if OSMO_IS_BIG_ENDIAN
uint8_t ft:3,
ctr:3,
amr_f:1,
amr_q:1;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#elif OSMO_IS_LITTLE_ENDIAN
uint8_t amr_q:1,
amr_f:1,
ctr:3,
@ -31,10 +33,10 @@ struct osmux_hdr {
uint8_t seq;
#define OSMUX_CID_MAX 255 /* determined by circuit_id */
uint8_t circuit_id;
#if __BYTE_ORDER == __BIG_ENDIAN
#if OSMO_IS_BIG_ENDIAN
uint8_t amr_ft:4,
amr_cmr:4;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#elif OSMO_IS_LITTLE_ENDIAN
uint8_t amr_cmr:4,
amr_ft:4;
#endif

View File

@ -1,16 +1,18 @@
#ifndef _OSMO_RTP_H_
#define _OSMO_RTP_H_
#include <osmocom/core/endian.h>
/* RTP header as defined by RFC 3550 */
struct rtp_hdr {
#if __BYTE_ORDER == __LITTLE_ENDIAN
#if OSMO_IS_LITTLE_ENDIAN
uint8_t csrc_count:4,
extension:1,
padding:1,
version:2;
uint8_t payload_type:7,
marker:1;
#elif __BYTE_ORDER == __BIG_ENDIAN
#elif OSMO_IS_BIG_ENDIAN
uint8_t version:2,
padding:1,
extension:1,

View File

@ -1,6 +1,5 @@
#include <stdint.h>
#include <sys/time.h>
#include <endian.h>
#include <errno.h>
#include <string.h> /* for memcpy. */
#include <arpa/inet.h> /* for ntohs. */