diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-05-15 12:48:30 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-05-15 13:42:03 +0200 |
commit | bfe62e5781e3ee895a44ca9ccc155ff87c42bf43 (patch) | |
tree | 00e488e16dc4326816a4e22d111508956ae5315b | |
parent | 50ef73377cb9235adafe673c2bfa7a9dc02c0c02 (diff) |
libosmogb: Convert to use new endian conversion helpers
Change-Id: I5ed17702cd9487e1cab6bae39802aa11fb6a37b0
-rw-r--r-- | src/gb/gprs_bssgp.c | 61 | ||||
-rw-r--r-- | src/gb/gprs_bssgp_bss.c | 44 | ||||
-rw-r--r-- | src/gb/gprs_bssgp_util.c | 9 | ||||
-rw-r--r-- | src/gb/gprs_ns.c | 31 | ||||
-rw-r--r-- | src/gb/gprs_ns_frgre.c | 19 | ||||
-rw-r--r-- | src/gb/gprs_ns_vty.c | 23 |
6 files changed, 91 insertions, 96 deletions
diff --git a/src/gb/gprs_bssgp.c b/src/gb/gprs_bssgp.c index fdbf7884..aa6e37bf 100644 --- a/src/gb/gprs_bssgp.c +++ b/src/gb/gprs_bssgp.c @@ -1,6 +1,6 @@ /* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */ -/* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> +/* (C) 2009-2017 by Harald Welte <laforge@gnumonks.org> * * All Rights Reserved * @@ -25,9 +25,9 @@ #include <errno.h> #include <stdint.h> -#include <netinet/in.h> - #include <osmocom/core/msgb.h> +#include <osmocom/core/byteswap.h> +#include <osmocom/core/bit16gen.h> #include <osmocom/gsm/tlv.h> #include <osmocom/core/talloc.h> #include <osmocom/core/rate_ctr.h> @@ -138,7 +138,7 @@ int bssgp_tx_suspend_ack(uint16_t nsei, uint32_t tlli, msgb_bvci(msg) = 0; /* Signalling */ bgph->pdu_type = BSSGP_PDUT_SUSPEND_ACK; - _tlli = htonl(tlli); + _tlli = osmo_htonl(tlli); msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); gsm48_construct_ra(ra, ra_id); msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); @@ -162,7 +162,7 @@ int bssgp_tx_suspend_nack(uint16_t nsei, uint32_t tlli, msgb_bvci(msg) = 0; /* Signalling */ bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; - _tlli = htonl(tlli); + _tlli = osmo_htonl(tlli); msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); gsm48_construct_ra(ra, ra_id); msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); @@ -186,7 +186,7 @@ int bssgp_tx_resume_ack(uint16_t nsei, uint32_t tlli, msgb_bvci(msg) = 0; /* Signalling */ bgph->pdu_type = BSSGP_PDUT_RESUME_ACK; - _tlli = htonl(tlli); + _tlli = osmo_htonl(tlli); msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); gsm48_construct_ra(ra, ra_id); msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); @@ -208,7 +208,7 @@ int bssgp_tx_resume_nack(uint16_t nsei, uint32_t tlli, msgb_bvci(msg) = 0; /* Signalling */ bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; - _tlli = htonl(tlli); + _tlli = osmo_htonl(tlli); msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); gsm48_construct_ra(ra, ra_id); msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); @@ -223,17 +223,16 @@ uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf) /* 6 octets RAC */ gsm48_parse_ra(raid, buf); /* 2 octets CID */ - return ntohs(*(uint16_t *) (buf+6)); + return osmo_load16be(buf+6); } int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, uint16_t cid) { - uint16_t *out_cid = (uint16_t *) (buf + 6); /* 6 octets RAC */ gsm48_construct_ra(buf, raid); /* 2 octets CID */ - *out_cid = htons(cid); + osmo_store16be(cid, buf+6); return 8; } @@ -247,7 +246,7 @@ static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, uint16_t nsei = msgb_nsei(msg); uint16_t bvci; - bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); + bvci = tlvp_val16be(tp, BSSGP_IE_BVCI); DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx RESET cause=%s\n", bvci, bssgp_cause_str(*TLVP_VAL(tp, BSSGP_IE_CAUSE))); @@ -297,7 +296,7 @@ static int bssgp_rx_bvc_block(struct msgb *msg, struct tlv_parsed *tp) uint16_t bvci; struct bssgp_bvc_ctx *ptp_ctx; - bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); + bvci = tlvp_val16be(tp, BSSGP_IE_BVCI); if (bvci == BVCI_SIGNALLING) { /* 8.3.2: Signalling BVC shall never be blocked */ LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " @@ -335,7 +334,7 @@ static int bssgp_rx_bvc_unblock(struct msgb *msg, struct tlv_parsed *tp) uint16_t bvci; struct bssgp_bvc_ctx *ptp_ctx; - bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); + bvci = tlvp_val16be(tp, BSSGP_IE_BVCI); if (bvci == BVCI_SIGNALLING) { /* 8.3.2: Signalling BVC shall never be blocked */ LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " @@ -374,7 +373,7 @@ static int bssgp_rx_ul_ud(struct msgb *msg, struct tlv_parsed *tp, struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); /* extract TLLI and parse TLV IEs */ - msgb_tlli(msg) = ntohl(budh->tlli); + msgb_tlli(msg) = osmo_ntohl(budh->tlli); DEBUGP(DBSSGP, "BSSGP TLLI=0x%08x Rx UPLINK-UNITDATA\n", msgb_tlli(msg)); @@ -416,7 +415,7 @@ static int bssgp_rx_suspend(struct msgb *msg, struct tlv_parsed *tp) return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); } - tlli = ntohl(tlvp_val32_unal(tp, BSSGP_IE_TLLI)); + tlli = tlvp_val32be(tp, BSSGP_IE_TLLI); DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=0x%08x Rx SUSPEND\n", ns_bvci, tlli); @@ -458,7 +457,7 @@ static int bssgp_rx_resume(struct msgb *msg, struct tlv_parsed *tp) return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); } - tlli = ntohl(tlvp_val32_unal(tp, BSSGP_IE_TLLI)); + tlli = tlvp_val32be(tp, BSSGP_IE_TLLI); suspend_ref = *TLVP_VAL(tp, BSSGP_IE_SUSPEND_REF_NR); DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=0x%08x Rx RESUME\n", ns_bvci, tlli); @@ -500,7 +499,7 @@ static int bssgp_rx_llc_disc(struct msgb *msg, struct tlv_parsed *tp, } if (TLVP_PRESENT(tp, BSSGP_IE_TLLI)) - tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); + tlli = tlvp_val32be(tp, BSSGP_IE_TLLI); DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=%08x Rx LLC DISCARDED\n", ctx->bvci, tlli); @@ -806,17 +805,13 @@ static int bssgp_rx_fc_bvc(struct msgb *msg, struct tlv_parsed *tp, } /* 11.3.5 Bucket Size in 100 octets unit */ - bctx->fc->bucket_size_max = 100 * - ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVC_BUCKET_SIZE)); + bctx->fc->bucket_size_max = 100 * tlvp_val16be(tp, BSSGP_IE_BVC_BUCKET_SIZE); /* 11.3.4 Bucket Leak Rate in 100 bits/sec unit */ - bctx->fc->bucket_leak_rate = 100 * - ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BUCKET_LEAK_RATE)) / 8; + bctx->fc->bucket_leak_rate = 100 * tlvp_val16be(tp, BSSGP_IE_BUCKET_LEAK_RATE) / 8; /* 11.3.2 in octets */ - bctx->bmax_default_ms = - ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BMAX_DEFAULT_MS)); + bctx->bmax_default_ms = tlvp_val16be(tp, BSSGP_IE_BMAX_DEFAULT_MS); /* 11.3.32 Bucket Leak rate in 100bits/sec unit */ - bctx->r_default_ms = 100 * - ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_R_DEFAULT_MS)) / 8; + bctx->r_default_ms = 100 * tlvp_val16be(tp, BSSGP_IE_R_DEFAULT_MS) / 8; if (old_leak_rate != 0 && bctx->fc->bucket_leak_rate == 0) LOGP(DBSSGP, LOGL_NOTICE, "BSS instructs us to bucket leak " @@ -1042,7 +1037,7 @@ int bssgp_rcvmsg(struct msgb *msg) } if (bvci == BVCI_SIGNALLING && TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) - bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); + bvci = tlvp_val16be(&tp, BSSGP_IE_BVCI); /* look-up or create the BTS context for this BVC */ bctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); @@ -1095,7 +1090,7 @@ int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, uint16_t msg_len = msg->len; uint16_t bvci = msgb_bvci(msg); uint16_t nsei = msgb_nsei(msg); - uint16_t _pdu_lifetime = htons(pdu_lifetime); /* centi-seconds */ + uint16_t _pdu_lifetime = osmo_htons(pdu_lifetime); /* centi-seconds */ uint16_t drx_params; OSMO_ASSERT(dup != NULL); @@ -1134,7 +1129,7 @@ int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, /* Old TLLI to help BSS map from old->new */ if (dup->tlli) { - uint32_t tlli = htonl(*dup->tlli); + uint32_t tlli = osmo_htonl(*dup->tlli); msgb_tvlv_push(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &tlli); } @@ -1148,7 +1143,7 @@ int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, } /* DRX parameters */ - drx_params = htons(dup->drx_parms); + drx_params = osmo_htons(dup->drx_parms); msgb_tvlv_push(msg, BSSGP_IE_DRX_PARAMS, 2, (uint8_t *) &drx_params); @@ -1165,7 +1160,7 @@ int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, /* prepend the QoS profile, TLLI and pdu type */ budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); memcpy(budh->qos_profile, dup->qos_profile, sizeof(budh->qos_profile)); - budh->tlli = htonl(msgb_tlli(msg)); + budh->tlli = osmo_htonl(msgb_tlli(msg)); budh->pdu_type = BSSGP_PDUT_DL_UNITDATA; rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]); @@ -1188,7 +1183,7 @@ int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, struct msgb *msg = bssgp_msgb_alloc(); struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); - uint16_t drx_params = htons(pinfo->drx_params); + uint16_t drx_params = osmo_htons(pinfo->drx_params); uint8_t mi[10]; int imsi_len = gsm48_generate_mid_from_imsi(mi, pinfo->imsi); uint8_t ra[6]; @@ -1226,7 +1221,7 @@ int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, break; case BSSGP_PAGING_BVCI: { - uint16_t bvci = htons(pinfo->bvci); + uint16_t bvci = osmo_htons(pinfo->bvci); msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *)&bvci); } break; @@ -1237,7 +1232,7 @@ int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, /* Optional (P-)TMSI */ if (pinfo->ptmsi) { - uint32_t ptmsi = htonl(*pinfo->ptmsi); + uint32_t ptmsi = osmo_htonl(*pinfo->ptmsi); msgb_tvlv_put(msg, BSSGP_IE_TMSI, 4, (uint8_t *) &ptmsi); } diff --git a/src/gb/gprs_bssgp_bss.c b/src/gb/gprs_bssgp_bss.c index 73c13509..93af98f3 100644 --- a/src/gb/gprs_bssgp_bss.c +++ b/src/gb/gprs_bssgp_bss.c @@ -1,6 +1,6 @@ /* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */ -/* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> +/* (C) 2009-2017 by Harald Welte <laforge@gnumonks.org> * * All Rights Reserved * @@ -22,9 +22,8 @@ #include <errno.h> #include <stdint.h> -#include <netinet/in.h> - #include <osmocom/core/msgb.h> +#include <osmocom/core/byteswap.h> #include <osmocom/core/rate_ctr.h> #include <osmocom/gsm/tlv.h> #include <osmocom/core/talloc.h> @@ -38,7 +37,7 @@ uint8_t *bssgp_msgb_tlli_put(struct msgb *msg, uint32_t tlli) { - uint32_t _tlli = htonl(tlli); + uint32_t _tlli = osmo_htonl(tlli); return msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); } @@ -159,7 +158,7 @@ int bssgp_tx_radio_status_tmsi(struct bssgp_bvc_ctx *bctx, uint8_t cause, uint32_t tmsi) { struct msgb *msg = common_tx_radio_status(bctx); - uint32_t _tmsi = htonl(tmsi); + uint32_t _tmsi = osmo_htonl(tmsi); if (!msg) return -ENOMEM; @@ -196,8 +195,8 @@ int bssgp_tx_flush_ll_ack(struct bssgp_bvc_ctx *bctx, uint32_t tlli, struct msgb *msg = bssgp_msgb_alloc(); struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); - uint16_t _bvci_new = htons(bvci_new); - uint32_t _oct_aff = htonl(num_octets & 0xFFFFFF); + uint16_t _bvci_new = osmo_htons(bvci_new); + uint32_t _oct_aff = osmo_htonl(num_octets & 0xFFFFFF); msgb_nsei(msg) = bctx->nsei; msgb_bvci(msg) = 0; /* Signalling */ @@ -219,8 +218,8 @@ int bssgp_tx_llc_discarded(struct bssgp_bvc_ctx *bctx, uint32_t tlli, struct msgb *msg = bssgp_msgb_alloc(); struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); - uint16_t _bvci = htons(bctx->bvci); - uint32_t _oct_aff = htonl(num_octets & 0xFFFFFF); + uint16_t _bvci = osmo_htons(bctx->bvci); + uint32_t _oct_aff = osmo_htonl(num_octets & 0xFFFFFF); LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx LLC-DISCARDED " "TLLI=0x%04x, FRAMES=%u, OCTETS=%u\n", bctx->bvci, tlli, @@ -244,7 +243,7 @@ int bssgp_tx_bvc_block(struct bssgp_bvc_ctx *bctx, uint8_t cause) struct msgb *msg = bssgp_msgb_alloc(); struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); - uint16_t _bvci = htons(bctx->bvci); + uint16_t _bvci = osmo_htons(bctx->bvci); LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-BLOCK " "CAUSE=%s\n", bctx->bvci, bssgp_cause_str(cause)); @@ -265,7 +264,7 @@ int bssgp_tx_bvc_unblock(struct bssgp_bvc_ctx *bctx) struct msgb *msg = bssgp_msgb_alloc(); struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); - uint16_t _bvci = htons(bctx->bvci); + uint16_t _bvci = osmo_htons(bctx->bvci); LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-BLOCK\n", bctx->bvci); @@ -284,7 +283,7 @@ int bssgp_tx_bvc_reset(struct bssgp_bvc_ctx *bctx, uint16_t bvci, uint8_t cause) struct msgb *msg = bssgp_msgb_alloc(); struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); - uint16_t _bvci = htons(bvci); + uint16_t _bvci = osmo_htons(bvci); LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-RESET " "CAUSE=%s\n", bvci, bssgp_cause_str(cause)); @@ -327,19 +326,19 @@ int bssgp_tx_fc_bvc(struct bssgp_bvc_ctx *bctx, uint8_t tag, if ((bucket_size / 100) > 0xffff) return -EINVAL; - e_bucket_size = htons(bucket_size / 100); + e_bucket_size = osmo_htons(bucket_size / 100); if ((bucket_leak_rate * 8 / 100) > 0xffff) return -EINVAL; - e_leak_rate = htons((bucket_leak_rate * 8) / 100); + e_leak_rate = osmo_htons((bucket_leak_rate * 8) / 100); if ((bmax_default_ms / 100) > 0xffff) return -EINVAL; - e_bmax_default_ms = htons(bmax_default_ms / 100); + e_bmax_default_ms = osmo_htons(bmax_default_ms / 100); if ((r_default_ms * 8 / 100) > 0xffff) return -EINVAL; - e_r_default_ms = htons((r_default_ms * 8) / 100); + e_r_default_ms = osmo_htons((r_default_ms * 8) / 100); if (queue_delay_ms) { if ((*queue_delay_ms / 10) > 60000) @@ -347,7 +346,7 @@ int bssgp_tx_fc_bvc(struct bssgp_bvc_ctx *bctx, uint8_t tag, else if (*queue_delay_ms == 0xFFFFFFFF) e_queue_delay = 0xFFFF; else - e_queue_delay = htons(*queue_delay_ms / 10); + e_queue_delay = osmo_htons(*queue_delay_ms / 10); } msg = bssgp_msgb_alloc(); @@ -408,7 +407,7 @@ int bssgp_tx_fc_ms(struct bssgp_bvc_ctx *bctx, uint32_t tlli, uint8_t tag, msgb_bvci(msg) = bctx->bvci; bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_MS; - e_tlli = htonl(tlli); + e_tlli = osmo_htonl(tlli); msgb_tvlv_put(msg, BSSGP_IE_TLLI, sizeof(e_tlli), (uint8_t *)&e_tlli); msgb_tvlv_put(msg, BSSGP_IE_TAG, sizeof(tag), (uint8_t *)&tag); msgb_tvlv_put(msg, BSSGP_IE_MS_BUCKET_SIZE, @@ -454,7 +453,7 @@ int bssgp_tx_ul_ud(struct bssgp_bvc_ctx *bctx, uint32_t tlli, /* User Data Header */ budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); - budh->tlli = htonl(tlli); + budh->tlli = osmo_htonl(tlli); memcpy(budh->qos_profile, qos_profile, 3); budh->pdu_type = BSSGP_PDUT_UL_UNITDATA; @@ -508,7 +507,7 @@ int bssgp_rx_paging(struct bssgp_paging_info *pinfo, /* DRX Parameters */ if (!TLVP_PRESENT(&tp, BSSGP_IE_DRX_PARAMS)) goto err_mand_ie; - pinfo->drx_params = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_DRX_PARAMS)); + pinfo->drx_params = tlvp_val16be(&tp, BSSGP_IE_DRX_PARAMS); /* Scope */ if (TLVP_PRESENT(&tp, BSSGP_IE_BSS_AREA_ID)) { @@ -525,7 +524,7 @@ int bssgp_rx_paging(struct bssgp_paging_info *pinfo, gsm48_parse_ra(&pinfo->raid, ra); } else if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { pinfo->scope = BSSGP_PAGING_BVCI; - pinfo->bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); + pinfo->bvci = tlvp_val16be(&tp, BSSGP_IE_BVCI); } else return -EINVAL; @@ -545,8 +544,7 @@ int bssgp_rx_paging(struct bssgp_paging_info *pinfo, TLVP_LEN(&tp, BSSGP_IE_TMSI) >= 4) { if (!pinfo->ptmsi) pinfo->ptmsi = talloc_zero_size(pinfo, sizeof(uint32_t)); - *(pinfo->ptmsi) = ntohl(*(uint32_t *) - TLVP_VAL(&tp, BSSGP_IE_TMSI)); + *(pinfo->ptmsi) = osmo_load32be(TLVP_VAL(&tp, BSSGP_IE_TMSI)); } return 0; diff --git a/src/gb/gprs_bssgp_util.c b/src/gb/gprs_bssgp_util.c index 6fff3621..88916c17 100644 --- a/src/gb/gprs_bssgp_util.c +++ b/src/gb/gprs_bssgp_util.c @@ -1,6 +1,6 @@ /* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */ -/* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> +/* (C) 2009-2017 by Harald Welte <laforge@gnumonks.org> * * All Rights Reserved * @@ -22,9 +22,8 @@ #include <errno.h> #include <stdint.h> -#include <netinet/in.h> - #include <osmocom/core/msgb.h> +#include <osmocom/core/byteswap.h> #include <osmocom/gsm/tlv.h> #include <osmocom/core/talloc.h> #include <osmocom/gprs/gprs_bssgp.h> @@ -168,7 +167,7 @@ int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei, msgb_bvci(msg) = ns_bvci; bgph->pdu_type = pdu_type; - _bvci = htons(bvci); + _bvci = osmo_htons(bvci); msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); return gprs_ns_sendmsg(bssgp_nsi, msg); @@ -203,7 +202,7 @@ int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg) bgph->pdu_type = BSSGP_PDUT_STATUS; msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause); if (bvci) { - uint16_t _bvci = htons(*bvci); + uint16_t _bvci = osmo_htons(*bvci); msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); } msgb_tvlv_put(msg, BSSGP_IE_PDU_IN_ERROR, diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c index 9a2a114f..d0c5a177 100644 --- a/src/gb/gprs_ns.c +++ b/src/gb/gprs_ns.c @@ -71,6 +71,7 @@ #include <arpa/inet.h> #include <osmocom/core/msgb.h> +#include <osmocom/core/byteswap.h> #include <osmocom/gsm/tlv.h> #include <osmocom/core/talloc.h> #include <osmocom/core/select.h> @@ -404,8 +405,8 @@ int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause) { struct msgb *msg = gprs_ns_msgb_alloc(); struct gprs_ns_hdr *nsh; - uint16_t nsvci = htons(nsvc->nsvci); - uint16_t nsei = htons(nsvc->nsei); + uint16_t nsvci = osmo_htons(nsvc->nsvci); + uint16_t nsei = osmo_htons(nsvc->nsei); log_set_context(LOG_CTX_GB_NSVC, nsvc); @@ -437,11 +438,11 @@ int gprs_ns_tx_status(struct gprs_nsvc *nsvc, uint8_t cause, { struct msgb *msg = gprs_ns_msgb_alloc(); struct gprs_ns_hdr *nsh; - uint16_t nsvci = htons(nsvc->nsvci); + uint16_t nsvci = osmo_htons(nsvc->nsvci); log_set_context(LOG_CTX_GB_NSVC, nsvc); - bvci = htons(bvci); + bvci = osmo_htons(bvci); if (!msg) return -ENOMEM; @@ -490,7 +491,7 @@ int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause) { struct msgb *msg = gprs_ns_msgb_alloc(); struct gprs_ns_hdr *nsh; - uint16_t nsvci = htons(nsvc->nsvci); + uint16_t nsvci = osmo_htons(nsvc->nsvci); log_set_context(LOG_CTX_GB_NSVC, nsvc); @@ -665,8 +666,8 @@ static int gprs_ns_tx_reset_ack(struct gprs_nsvc *nsvc) if (!msg) return -ENOMEM; - nsvci = htons(nsvc->nsvci); - nsei = htons(nsvc->nsei); + nsvci = osmo_htons(nsvc->nsvci); + nsei = osmo_htons(nsvc->nsei); msg->l2h = msgb_put(msg, sizeof(*nsh)); nsh = (struct gprs_ns_hdr *) msg->l2h; @@ -849,8 +850,8 @@ static int gprs_ns_rx_reset(struct gprs_nsvc **nsvc, struct msgb *msg) } cause = *(uint8_t *) TLVP_VAL(&tp, NS_IE_CAUSE); - nsvci = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_VCI)); - nsei = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_NSEI)); + nsvci = tlvp_val16be(&tp, NS_IE_VCI); + nsei = tlvp_val16be(&tp, NS_IE_NSEI); LOGP(DNS, LOGL_INFO, "NSVCI=%u%s Rx NS RESET (NSEI=%u, NSVCI=%u, cause=%s)\n", (*nsvc)->nsvci, (*nsvc)->nsvci_is_valid ? "" : "(invalid)", @@ -957,8 +958,8 @@ static int gprs_ns_rx_reset_ack(struct gprs_nsvc **nsvc, struct msgb *msg) return -EINVAL; } - nsvci = ntohs(tlvp_val16_unal(&tp, NS_IE_VCI)); - nsei = ntohs(tlvp_val16_unal(&tp, NS_IE_NSEI)); + nsvci = tlvp_val16be(&tp, NS_IE_VCI); + nsei = tlvp_val16be(&tp, NS_IE_NSEI); LOGP(DNS, LOGL_INFO, "NSVCI=%u%s Rx NS RESET ACK (NSEI=%u, NSVCI=%u)\n", (*nsvc)->nsvci, (*nsvc)->nsvci_is_valid ? "" : "(invalid)", @@ -1145,7 +1146,7 @@ const char *gprs_ns_ll_str(struct gprs_nsvc *nsvc) static char buf[80]; snprintf(buf, sizeof(buf), "%s:%u", inet_ntoa(nsvc->ip.bts_addr.sin_addr), - ntohs(nsvc->ip.bts_addr.sin_port)); + osmo_ntohs(nsvc->ip.bts_addr.sin_port)); buf[sizeof(buf) - 1] = '\0'; return buf; @@ -1271,8 +1272,8 @@ int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg, CHECK_TX_RC(rc, fallback_nsvc); return -EINVAL; } - nsvci = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_VCI)); - nsei = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_NSEI)); + nsvci = tlvp_val16be(&tp, NS_IE_VCI); + nsei = tlvp_val16be(&tp, NS_IE_NSEI); /* Check if we already know this NSVCI, the remote end might * simply have changed addresses, or it is a SGSN */ existing_nsvc = gprs_nsvc_by_nsvci(nsi, nsvci); @@ -1554,7 +1555,7 @@ int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi) struct in_addr in; int ret; - in.s_addr = htonl(nsi->nsip.local_ip); + in.s_addr = osmo_htonl(nsi->nsip.local_ip); nsi->nsip.fd.cb = nsip_fd_cb; nsi->nsip.fd.data = nsi; diff --git a/src/gb/gprs_ns_frgre.c b/src/gb/gprs_ns_frgre.c index 68225417..285a9a07 100644 --- a/src/gb/gprs_ns_frgre.c +++ b/src/gb/gprs_ns_frgre.c @@ -32,6 +32,7 @@ #include <arpa/inet.h> #include <osmocom/core/select.h> +#include <osmocom/core/byteswap.h> #include <osmocom/core/msgb.h> #include <osmocom/core/talloc.h> #include <osmocom/core/socket.h> @@ -121,7 +122,7 @@ static int handle_rx_gre_ipv4(struct osmo_fd *bfd, struct msgb *msg, } inner_greh = (struct gre_hdr *) ((uint8_t *)inner_iph + iph->ihl*4); - if (inner_greh->ptype != htons(GRE_PTYPE_KAR)) { + if (inner_greh->ptype != osmo_htons(GRE_PTYPE_KAR)) { LOGP(DNS, LOGL_ERROR, "GRE keepalive inner GRE type != 0\n"); return -EIO; } @@ -187,10 +188,10 @@ static struct msgb *read_nsfrgre_msg(struct osmo_fd *bfd, int *error, greh = (struct gre_hdr *) (msg->data + iph->ihl*4); if (greh->flags) { LOGP(DNS, LOGL_NOTICE, "Unknown GRE flags 0x%04x\n", - ntohs(greh->flags)); + osmo_ntohs(greh->flags)); } - switch (ntohs(greh->ptype)) { + switch (osmo_ntohs(greh->ptype)) { case GRE_PTYPE_IPv4: /* IPv4 messages might be GRE keepalives */ *error = handle_rx_gre_ipv4(bfd, msg, iph, greh); @@ -201,7 +202,7 @@ static struct msgb *read_nsfrgre_msg(struct osmo_fd *bfd, int *error, break; default: LOGP(DNS, LOGL_NOTICE, "Unknown GRE protocol 0x%04x != FR\n", - ntohs(greh->ptype)); + osmo_ntohs(greh->ptype)); *error = -EIO; goto out_err; break; @@ -231,7 +232,7 @@ static struct msgb *read_nsfrgre_msg(struct osmo_fd *bfd, int *error, msg->l2h = frh+2; /* Store DLCI in NETWORK BYTEORDER in sockaddr port member */ - saddr->sin_port = htons(dlci); + saddr->sin_port = osmo_htons(dlci); return msg; @@ -255,7 +256,7 @@ static int handle_nsfrgre_read(struct osmo_fd *bfd) if (!msg) return rc; - dlci = ntohs(saddr.sin_port); + dlci = osmo_ntohs(saddr.sin_port); if (dlci == 0 || dlci == 1023) { LOGP(DNS, LOGL_INFO, "Received FR on LMI DLCI %u - ignoring\n", dlci); @@ -281,7 +282,7 @@ int gprs_ns_frgre_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg) int rc; struct gprs_ns_inst *nsi = nsvc->nsi; struct sockaddr_in daddr; - uint16_t dlci = ntohs(nsvc->frgre.bts_addr.sin_port); + uint16_t dlci = osmo_ntohs(nsvc->frgre.bts_addr.sin_port); uint8_t *frh; struct gre_hdr *greh; @@ -298,7 +299,7 @@ int gprs_ns_frgre_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg) /* Prepend the GRE header */ greh = (struct gre_hdr *) msgb_push(msg, sizeof(*greh)); greh->flags = 0; - greh->ptype = htons(GRE_PTYPE_FR); + greh->ptype = osmo_htons(GRE_PTYPE_FR); rc = sendto(nsi->frgre.fd.fd, msg->data, msg->len, 0, (struct sockaddr *)&daddr, sizeof(daddr)); @@ -325,7 +326,7 @@ int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi) struct in_addr in; int rc; - in.s_addr = htonl(nsi->frgre.local_ip); + in.s_addr = osmo_htonl(nsi->frgre.local_ip); /* Make sure we close any existing socket before changing it */ if (nsi->frgre.fd.fd) diff --git a/src/gb/gprs_ns_vty.c b/src/gb/gprs_ns_vty.c index 6de74dd1..bdccb3ff 100644 --- a/src/gb/gprs_ns_vty.c +++ b/src/gb/gprs_ns_vty.c @@ -27,6 +27,7 @@ #include <arpa/inet.h> #include <osmocom/core/msgb.h> +#include <osmocom/core/byteswap.h> #include <osmocom/gsm/tlv.h> #include <osmocom/core/talloc.h> #include <osmocom/core/select.h> @@ -100,7 +101,7 @@ static int config_write_ns(struct vty *vty) inet_ntoa(nsvc->ip.bts_addr.sin_addr), VTY_NEWLINE); vty_out(vty, " nse %u remote-port %u%s", - nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port), + nsvc->nsei, osmo_ntohs(nsvc->ip.bts_addr.sin_port), VTY_NEWLINE); break; case GPRS_NS_LL_FR_GRE: @@ -111,7 +112,7 @@ static int config_write_ns(struct vty *vty) inet_ntoa(nsvc->frgre.bts_addr.sin_addr), VTY_NEWLINE); vty_out(vty, " nse %u fr-dlci %u%s", - nsvc->nsei, ntohs(nsvc->frgre.bts_addr.sin_port), + nsvc->nsei, osmo_ntohs(nsvc->frgre.bts_addr.sin_port), VTY_NEWLINE); default: break; @@ -124,7 +125,7 @@ static int config_write_ns(struct vty *vty) vty_nsi->timeout[i], VTY_NEWLINE); if (vty_nsi->nsip.local_ip) { - ia.s_addr = htonl(vty_nsi->nsip.local_ip); + ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip); vty_out(vty, " encapsulation udp local-ip %s%s", inet_ntoa(ia), VTY_NEWLINE); } @@ -138,7 +139,7 @@ static int config_write_ns(struct vty *vty) vty_out(vty, " encapsulation framerelay-gre enabled %u%s", vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE); if (vty_nsi->frgre.local_ip) { - ia.s_addr = htonl(vty_nsi->frgre.local_ip); + ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip); vty_out(vty, " encapsulation framerelay-gre local-ip %s%s", inet_ntoa(ia), VTY_NEWLINE); } @@ -165,7 +166,7 @@ static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats) vty_out(vty, ", %s %15s:%u", nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE", inet_ntoa(nsvc->ip.bts_addr.sin_addr), - ntohs(nsvc->ip.bts_addr.sin_port)); + osmo_ntohs(nsvc->ip.bts_addr.sin_port)); vty_out(vty, "%s", VTY_NEWLINE); if (stats) { vty_out_rate_ctr_group(vty, " ", nsvc->ctrg); @@ -178,11 +179,11 @@ static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats) struct gprs_nsvc *nsvc; struct in_addr ia; - ia.s_addr = htonl(vty_nsi->nsip.local_ip); + ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip); vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s", inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE); - ia.s_addr = htonl(vty_nsi->frgre.local_ip); + ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip); vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s", inet_ntoa(ia), VTY_NEWLINE); @@ -309,7 +310,7 @@ DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd, return CMD_WARNING; } - nsvc->ip.bts_addr.sin_port = htons(port); + nsvc->ip.bts_addr.sin_port = osmo_htons(port); return CMD_SUCCESS; } @@ -336,7 +337,7 @@ DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, return CMD_WARNING; } - nsvc->frgre.bts_addr.sin_port = htons(dlci); + nsvc->frgre.bts_addr.sin_port = osmo_htons(dlci); return CMD_SUCCESS; } @@ -441,7 +442,7 @@ DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd, struct in_addr ia; inet_aton(argv[0], &ia); - vty_nsi->nsip.local_ip = ntohl(ia.s_addr); + vty_nsi->nsip.local_ip = osmo_ntohl(ia.s_addr); return CMD_SUCCESS; } @@ -482,7 +483,7 @@ DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd, return CMD_WARNING; } inet_aton(argv[0], &ia); - vty_nsi->frgre.local_ip = ntohl(ia.s_addr); + vty_nsi->frgre.local_ip = osmo_ntohl(ia.s_addr); return CMD_SUCCESS; } |