aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-10-19 19:04:03 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-10-30 21:24:10 +0100
commit63f29d6f73d069479b5269b924df0638da6c88e5 (patch)
treebcea1fae4a979883e60d6b6ea291e80338f15f03
parent6ca0a9076e77146e0d5b6ce5f1330b15c5699aa5 (diff)
encoding: Move the functions into the encoding class
Add some TODO to this class. E.g. they could all work on the bitvec and the parameter handling could better.
-rw-r--r--src/Makefile.am3
-rw-r--r--src/bts.cpp5
-rw-r--r--src/encoding.cpp15
-rw-r--r--src/encoding.h66
-rw-r--r--src/gprs_rlcmac.cpp3
-rw-r--r--src/gprs_rlcmac.h31
-rw-r--r--src/gprs_rlcmac_data.cpp13
7 files changed, 88 insertions, 48 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f9bb17f6..ab72aa3c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -80,7 +80,8 @@ noinst_HEADERS = \
femtobts.h \
tbf.h \
bts.h \
- poll_controller.h
+ poll_controller.h \
+ encoding.h
osmo_pcu_SOURCES = pcu_main.cpp
diff --git a/src/bts.cpp b/src/bts.cpp
index 2b7a93c2..3d0fc335 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -21,6 +21,7 @@
#include <bts.h>
#include <poll_controller.h>
#include <tbf.h>
+#include <encoding.h>
#include <gprs_rlcmac.h>
#include <gprs_debug.h>
@@ -225,7 +226,7 @@ struct msgb *gprs_rlcmac_pdch::packet_paging_request()
talloc_free(pag);
return NULL;
}
- wp = write_packet_paging_request(pag_vec);
+ wp = Encoding::write_packet_paging_request(pag_vec);
/* loop until message is full */
while (pag) {
@@ -259,7 +260,7 @@ struct msgb *gprs_rlcmac_pdch::packet_paging_request()
llist_add_tail(&pag->list, &paging_list);
break;
}
- write_repeated_page_info(pag_vec, wp, pag->identity_lv[0],
+ Encoding::write_repeated_page_info(pag_vec, wp, pag->identity_lv[0],
pag->identity_lv + 1, pag->chan_needed);
continue_next:
diff --git a/src/encoding.cpp b/src/encoding.cpp
index 4dd94445..26ac71ec 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -19,12 +19,13 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <encoding.h>
#include <gprs_rlcmac.h>
#include <tbf.h>
#include <gprs_debug.h>
// GSM 04.08 9.1.18 Immediate assignment
-int write_immediate_assignment(
+int Encoding::write_immediate_assignment(
struct gprs_rlcmac_bts *bts,
bitvec * dest, uint8_t downlink, uint8_t ra,
uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc,
@@ -160,7 +161,7 @@ int write_immediate_assignment(
}
/* generate uplink assignment */
-void write_packet_uplink_assignment(
+void Encoding::write_packet_uplink_assignment(
struct gprs_rlcmac_bts *bts,
bitvec * dest, uint8_t old_tfi,
uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
@@ -241,7 +242,7 @@ void write_packet_uplink_assignment(
/* generate downlink assignment */
-void write_packet_downlink_assignment(RlcMacDownlink_t * block, uint8_t old_tfi,
+void Encoding::write_packet_downlink_assignment(RlcMacDownlink_t * block, uint8_t old_tfi,
uint8_t old_downlink, struct gprs_rlcmac_tbf *tbf, uint8_t poll,
uint8_t alpha, uint8_t gamma, int8_t ta_idx, uint8_t ta_ts)
{
@@ -314,7 +315,7 @@ void write_packet_downlink_assignment(RlcMacDownlink_t * block, uint8_t old_tfi,
}
/* generate paging request */
-int write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len)
+int Encoding::write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len)
{
unsigned wp = 0;
int plen;
@@ -351,7 +352,7 @@ int write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len)
}
/* generate uplink ack */
-void write_packet_uplink_ack(struct gprs_rlcmac_bts *bts,
+void Encoding::write_packet_uplink_ack(struct gprs_rlcmac_bts *bts,
RlcMacDownlink_t * block, struct gprs_rlcmac_tbf *tbf,
uint8_t final)
{
@@ -412,7 +413,7 @@ void write_packet_uplink_ack(struct gprs_rlcmac_bts *bts,
block->u.Packet_Uplink_Ack_Nack.u.PU_AckNack_GPRS_Struct.Common_Uplink_Ack_Nack_Data.Exist_Power_Control_Parameters = 0x0;
}
-unsigned write_packet_paging_request(bitvec * dest)
+unsigned Encoding::write_packet_paging_request(bitvec * dest)
{
unsigned wp = 0;
@@ -429,7 +430,7 @@ unsigned write_packet_paging_request(bitvec * dest)
return wp;
}
-unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
+unsigned Encoding::write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
uint8_t *identity, uint8_t chan_needed)
{
bitvec_write_field(dest, wp,0x1,1); // Repeated Page info exists
diff --git a/src/encoding.h b/src/encoding.h
new file mode 100644
index 00000000..d0f8f0ab
--- /dev/null
+++ b/src/encoding.h
@@ -0,0 +1,66 @@
+/* encoding.cpp
+ *
+ * Copyright (C) 2012 Ivan Klyuchnikov
+ * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
+ * Copyright (C) 2013 by Holger Hans Peter Freyther
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#pragma once
+
+#include <stdint.h>
+#include <gsm_rlcmac.h>
+
+struct gprs_rlcmac_bts;
+struct gprs_rlcmac_tbf;
+struct bitvec;
+
+/**
+ * I help with encoding data into CSN1 messages.
+ * TODO: Nobody can remember a function signature like this. One should
+ * fill out a struct with the request parameters and then hand the struct
+ * to the code.
+ */
+class Encoding {
+public:
+ static int write_immediate_assignment(
+ struct gprs_rlcmac_bts *bts,
+ bitvec * dest, uint8_t downlink, uint8_t ra,
+ uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc,
+ uint8_t tfi, uint8_t usf, uint32_t tlli, uint8_t polling,
+ uint32_t fn, uint8_t single_block, uint8_t alpha, uint8_t gamma,
+ int8_t ta_idx);
+
+ static void write_packet_uplink_assignment(
+ struct gprs_rlcmac_bts *bts,
+ bitvec * dest, uint8_t old_tfi,
+ uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
+ struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t alpha,
+ uint8_t gamma, int8_t ta_idx);
+
+ static void write_packet_downlink_assignment(RlcMacDownlink_t * block, uint8_t old_tfi,
+ uint8_t old_downlink, struct gprs_rlcmac_tbf *tbf, uint8_t poll,
+ uint8_t alpha, uint8_t gamma, int8_t ta_idx, uint8_t ta_ts);
+
+ static void write_packet_uplink_ack(struct gprs_rlcmac_bts *bts, RlcMacDownlink_t * block, struct gprs_rlcmac_tbf *tbf,
+ uint8_t final);
+
+ static int write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len);
+
+ static unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
+ uint8_t *identity, uint8_t chan_needed);
+
+ static unsigned write_packet_paging_request(bitvec * dest);
+};
diff --git a/src/gprs_rlcmac.cpp b/src/gprs_rlcmac.cpp
index edb2d1ff..da48b6b6 100644
--- a/src/gprs_rlcmac.cpp
+++ b/src/gprs_rlcmac.cpp
@@ -23,6 +23,7 @@
#include <pcu_l1_if.h>
#include <gprs_rlcmac.h>
#include <bts.h>
+#include <encoding.h>
#include <tbf.h>
@@ -304,7 +305,7 @@ int gprs_rlcmac_paging_request(uint8_t *ptmsi, uint16_t ptmsi_len,
LOGP(DRLCMAC, LOGL_NOTICE, "TX: [PCU -> BTS] Paging Request (CCCH)\n");
bitvec *paging_request = bitvec_alloc(23);
bitvec_unhex(paging_request, "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
- int plen = write_paging_request(paging_request, ptmsi, ptmsi_len);
+ int plen = Encoding::write_paging_request(paging_request, ptmsi, ptmsi_len);
pcu_l1if_tx_pch(paging_request, plen, (char *)imsi);
bitvec_free(paging_request);
diff --git a/src/gprs_rlcmac.h b/src/gprs_rlcmac.h
index d14f3805..bbd5e0c2 100644
--- a/src/gprs_rlcmac.h
+++ b/src/gprs_rlcmac.h
@@ -112,32 +112,6 @@ int gprs_rlcmac_rcv_block(struct gprs_rlcmac_bts *bts,
uint8_t trx, uint8_t ts, uint8_t *data, uint8_t len,
uint32_t fn, int8_t rssi);
-int write_immediate_assignment(
- struct gprs_rlcmac_bts *bts,
- bitvec * dest, uint8_t downlink, uint8_t ra,
- uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc,
- uint8_t tfi, uint8_t usf, uint32_t tlli, uint8_t polling,
- uint32_t fn, uint8_t single_block, uint8_t alpha, uint8_t gamma,
- int8_t ta_idx);
-
-void write_packet_uplink_assignment(
- struct gprs_rlcmac_bts *bts,
- bitvec * dest, uint8_t old_tfi,
- uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
- struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t alpha,
- uint8_t gamma, int8_t ta_idx);
-
-void write_packet_downlink_assignment(RlcMacDownlink_t * block, uint8_t old_tfi,
- uint8_t old_downlink, struct gprs_rlcmac_tbf *tbf, uint8_t poll,
- uint8_t alpha, uint8_t gamma, int8_t ta_idx, uint8_t ta_ts);
-
-
-
-void write_packet_uplink_ack(struct gprs_rlcmac_bts *bts, RlcMacDownlink_t * block, struct gprs_rlcmac_tbf *tbf,
- uint8_t final);
-
-int write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len);
-
int gprs_rlcmac_tx_ul_ud(gprs_rlcmac_tbf *tbf);
int gprs_rlcmac_poll_timeout(struct gprs_rlcmac_bts *bts, struct gprs_rlcmac_tbf *tbf);
@@ -169,11 +143,6 @@ int gprs_rlcmac_downlink_ack(struct gprs_rlcmac_bts *bts,
int gprs_rlcmac_paging_request(uint8_t *ptmsi, uint16_t ptmsi_len,
const char *imsi);
-unsigned write_packet_paging_request(bitvec * dest);
-
-unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
- uint8_t *identity, uint8_t chan_needed);
-
int gprs_rlcmac_rcv_data_block_acknowledged(struct gprs_rlcmac_bts *bts,
uint8_t trx, uint8_t ts,
uint8_t *data, uint8_t len, int8_t rssi);
diff --git a/src/gprs_rlcmac_data.cpp b/src/gprs_rlcmac_data.cpp
index bb268717..5eab066c 100644
--- a/src/gprs_rlcmac_data.cpp
+++ b/src/gprs_rlcmac_data.cpp
@@ -22,6 +22,7 @@
#include <gprs_rlcmac.h>
#include <pcu_l1_if.h>
#include <bts.h>
+#include <encoding.h>
#include <tbf.h>
extern void *tall_pcu_ctx;
@@ -710,7 +711,7 @@ struct msgb *gprs_rlcmac_send_uplink_ack(struct gprs_rlcmac_bts *bts,
bitvec_unhex(ack_vec,
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t);
- write_packet_uplink_ack(bts, mac_control_block, tbf, final);
+ Encoding::write_packet_uplink_ack(bts, mac_control_block, tbf, final);
encode_gsm_rlcmac_downlink(ack_vec, mac_control_block);
bitvec_pack(ack_vec, msgb_put(msg, 23));
bitvec_free(ack_vec);
@@ -1001,7 +1002,7 @@ struct msgb *gprs_rlcmac_send_packet_uplink_assignment(
}
bitvec_unhex(ass_vec,
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
- write_packet_uplink_assignment(bts, ass_vec, tbf->tfi,
+ Encoding::write_packet_uplink_assignment(bts, ass_vec, tbf->tfi,
(tbf->direction == GPRS_RLCMAC_DL_TBF), tbf->tlli,
tbf->tlli_valid, new_tbf, POLLING_ASSIGNMENT_UL, bts->alpha,
bts->gamma, -1);
@@ -1095,12 +1096,12 @@ int gprs_rlcmac_rcv_rach(struct gprs_rlcmac_bts *bts,
bitvec_unhex(immediate_assignment,
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
if (sb)
- plen = write_immediate_assignment(bts, immediate_assignment, 0, ra,
+ plen = Encoding::write_immediate_assignment(bts, immediate_assignment, 0, ra,
Fn, qta >> 2, bts->trx[trx].arfcn, ts,
bts->trx[trx].pdch[ts].tsc, 0, 0, 0, 0, sb_fn, 1,
bts->alpha, bts->gamma, -1);
else
- plen = write_immediate_assignment(bts, immediate_assignment, 0, ra,
+ plen = Encoding::write_immediate_assignment(bts, immediate_assignment, 0, ra,
Fn, tbf->ta, tbf->arfcn, tbf->first_ts, tbf->tsc,
tbf->tfi, tbf->dir.ul.usf[tbf->first_ts], 0, 0, 0, 0,
bts->alpha, bts->gamma, -1);
@@ -1681,7 +1682,7 @@ struct msgb *gprs_rlcmac_send_packet_downlink_assignment(
"2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
LOGP(DRLCMAC, LOGL_INFO, "TBF: START TFI: %u TLLI: 0x%08x Packet Downlink Assignment (PACCH)\n", new_tbf->tfi, new_tbf->tlli);
RlcMacDownlink_t * mac_control_block = (RlcMacDownlink_t *)talloc_zero(tall_pcu_ctx, RlcMacDownlink_t);
- write_packet_downlink_assignment(mac_control_block, tbf->tfi,
+ Encoding::write_packet_downlink_assignment(mac_control_block, tbf->tfi,
(tbf->direction == GPRS_RLCMAC_DL_TBF), new_tbf,
poll_ass_dl, bts->alpha, bts->gamma, -1, 0);
LOGP(DRLCMAC, LOGL_DEBUG, "+++++++++++++++++++++++++ TX : Packet Downlink Assignment +++++++++++++++++++++++++\n");
@@ -1721,7 +1722,7 @@ static void gprs_rlcmac_downlink_assignment(struct gprs_rlcmac_bts *bts,
bitvec_unhex(immediate_assignment, "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b");
/* use request reference that has maximum distance to current time,
* so the assignment will not conflict with possible RACH requests. */
- plen = write_immediate_assignment(bts, immediate_assignment, 1, 125,
+ plen = Encoding::write_immediate_assignment(bts, immediate_assignment, 1, 125,
(tbf->pdch[tbf->first_ts]->last_rts_fn + 21216) % 2715648, tbf->ta,
tbf->arfcn, tbf->first_ts, tbf->tsc, tbf->tfi, 0, tbf->tlli, poll,
tbf->poll_fn, 0, bts->alpha, bts->gamma, -1);