[PATCH] osmo-ttcn3-hacks[master]: RSL_Emulation: Pass ASP_IPA_EVENT_UP to RSL_CCHAN port

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6628

RSL_Emulation: Pass ASP_IPA_EVENT_UP to RSL_CCHAN port

When emulating the BSC side of RSL, this can be used by a test case
to wait for the RSL connection to be established.

Change-Id: Iad2f6e4cb6a8f3b77e452f36a83ec11e7554e6c7
---
M library/RSL_Emulation.ttcn
1 file changed, 6 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/28/6628/1

diff --git a/library/RSL_Emulation.ttcn b/library/RSL_Emulation.ttcn
index 5c7dc9c..bf6686a 100644
--- a/library/RSL_Emulation.ttcn
+++ b/library/RSL_Emulation.ttcn
@@ -53,7 +53,7 @@
 } with { extension "internal" };
 
 type port RSL_CCHAN_PT message {
-   inout ASP_RSL_Unitdata;
+   inout ASP_RSL_Unitdata, ASP_IPA_Event;
 } with { extension "internal" };
 
 
@@ -277,6 +277,7 @@
 
 
 function main(boolean bts_role := true) runs on RSL_Emulation_CT {
+   var ASP_IPA_Event evt;
var ASP_RSL_Unitdata rx_rsl;
var RSL_Message rx_rsl_msg;
var RSLDC_ChanRqd chan_rqd;
@@ -292,7 +293,10 @@
 
while (true) {
alt {
-   [] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) {
+   [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_UP}) {
+   }
+   [not bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_UP}) -> value evt {
+   CCHAN_PT.send(evt);
}
[bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_ID_ACK}) {

IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));

-- 
To view, visit https://gerrit.osmocom.org/6628
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iad2f6e4cb6a8f3b77e452f36a83ec11e7554e6c7
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 


[PATCH] osmo-ttcn3-hacks[master]: IPA_Emulation: Don't log IPAC_MSGT_ID_RESP as "Unknown/unsup...

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6626

IPA_Emulation: Don't log IPAC_MSGT_ID_RESP as "Unknown/unsupported"

Change-Id: I6ea3855a1f3d1cba6ac173b0f9cf9052d5d028fc
---
M library/IPA_Emulation.ttcnpp
1 file changed, 3 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/26/6626/1

diff --git a/library/IPA_Emulation.ttcnpp b/library/IPA_Emulation.ttcnpp
index 3508091..c3cfe8d 100644
--- a/library/IPA_Emulation.ttcnpp
+++ b/library/IPA_Emulation.ttcnpp
@@ -342,6 +342,9 @@
case (IPAC_MSGT_ID_GET) {
f_ccm_tx(f_ccm_make_id_resp(ccm));
}
+   case (IPAC_MSGT_ID_RESP) {
+   log("IPA ID RESP: ", ccm.u.resp);
+   }
case else {
log("Unknown/unsupported IPA CCM message type", ccm);
}

-- 
To view, visit https://gerrit.osmocom.org/6626
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ea3855a1f3d1cba6ac173b0f9cf9052d5d028fc
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 


[PATCH] osmo-ttcn3-hacks[master]: Add initial OsmoBTS test suite

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6629

Add initial OsmoBTS test suite

This Test suite implements the BSC-side of Abis RSL and is used to
test OsmoBTS.  It contains provisions for using L1CTL against
(virt_phy + osmo-bts-virtual) or (trxcon + fake_trx + osmo-bts-trx)
to also simulate the MS/Um side, bu those provisions are not used
yet.

Implemented tests currently are only related to RSL dedicated channel
activation / deactivation.

We still terminate OML inside OsmoBSC, and let the test suite deal
exclusively with RSL to keep complexity low.

Change-Id: I8ced0d29777aad3ec842d54eabea87dfcc943c79
---
M Makefile
A bts/BTS_Tests.ttcn
A bts/gen_links.sh
A bts/regen_makefile.sh
4 files changed, 315 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/29/6629/1

diff --git a/Makefile b/Makefile
index 2fcc561..3f2230b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-SUBDIRS=bsc bsc-nat ggsn_tests gprs_gb lapdm mgw msc selftest sgsn sysinfo
+SUBDIRS=bsc bsc-nat bts ggsn_tests gprs_gb lapdm mgw msc selftest sgsn sysinfo
 
 PARALLEL_MAKE:=-j4
 
diff --git a/bts/BTS_Tests.ttcn b/bts/BTS_Tests.ttcn
new file mode 100644
index 000..16372f7
--- /dev/null
+++ b/bts/BTS_Tests.ttcn
@@ -0,0 +1,261 @@
+module BTS_Tests {
+
+import from General_Types all;
+import from GSM_Types all;
+import from Osmocom_Types all;
+import from GSM_Types all;
+import from LAPDm_RAW_PT all;
+import from Osmocom_CTRL_Adapter all;
+
+import from RSL_Types all;
+import from IPA_Emulation all;
+import from RSL_Emulation all;
+
+modulepar {
+   charstring mp_rsl_ip := "127.0.0.2";
+   integer mp_rsl_port := 3003;
+}
+
+type component test_CT extends CTRL_Adapter_CT {
+   var IPA_Emulation_CT vc_IPA;
+
+   var RSL_Emulation_CT vc_RSL;
+   port RSL_CCHAN_PT RSL_CCHAN;
+}
+
+/* an individual call / channel */
+type component ConnHdlr extends RSL_DchanHdlr {
+   var lapdm_CT vc_LAPDm;
+   port LAPDm_PT L1;
+
+   timer g_Tguard;
+
+   var ConnHdlrPars g_pars;
+}
+
+function f_init_rsl(charstring id) runs on test_CT {
+   vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
+   vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
+
+   map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
+   connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
+   connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
+
+   vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
+   vc_RSL.start(RSL_Emulation.main(false));
+}
+
+type record ConnHdlrPars {
+   RslChannelNr chan_nr,
+   RSL_IE_ChannelMode chan_mode,
+   float t_guard
+}
+
+
+/* global init function */
+function f_init(charstring id) runs on test_CT {
+   f_init_rsl(id);
+   RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
+}
+
+type function void_fn(charstring id) runs on ConnHdlr;
+
+/* create a new test component */
+function f_start_handler(void_fn fn, ConnHdlrPars pars)
+runs on test_CT return ConnHdlr {
+   var charstring id := testcasename();
+   var ConnHdlr vc_conn;
+
+   vc_conn := ConnHdlr.create(id);
+   /* connect to RSL Emulation main component */
+   connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
+   connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
+
+   vc_conn.start(f_handler_init(fn, id, pars));
+   return vc_conn;
+}
+
+private altstep as_Tguard() runs on ConnHdlr {
+   [] g_Tguard.timeout {
+   setverdict(fail, "Tguard timeout");
+   self.stop;
+   }
+}
+
+/* first function started in ConnHdlr component */
+private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
+runs on ConnHdlr {
+   g_pars := pars;
+   g_chan_nr := pars.chan_nr;
+
+   /* start the L1 / LAPDm-Codec port to 'trxcon' or 'virt_phy' */
+/*
+   vc_LAPDm := lapdm_CT.create(id & "-L1");
+   connect(self:L1, vc_LAPDm:LAPDM_SP);
+   map(vc_LAPDm:L1CTL, system:L1CTL);
+   vc_LAPDm.start(LAPDmStart());
+*/
+
+   g_Tguard.start(pars.t_guard);
+   activate(as_Tguard());
+
+   f_rslem_register(0, pars.chan_nr);
+
+   /* call the user-supplied test case function */
+   fn.apply(id);
+}
+
+
+function f_rsl_chan_act(RSL_IE_ChannelMode mode) runs on RSL_DchanHdlr {
+   RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, mode));
+   alt {
+   [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) { }
+   [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
+   setverdict(fail, "Unexpected RF CHAN ACT NACK");
+   }
+   }
+}
+
+function f_rsl_chan_deact() runs on RSL_DchanHdlr {
+   timer T := 3.0;
+   RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
+   T.start;
+   alt {
+   [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) { }
+   [] T.timeout {
+   setverdict(fail, "Timeout waiting for RF CHAN REL ACK");
+   }
+   }
+}
+
+
+private template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
+   

[PATCH] osmo-ttcn3-hacks[master]: RSL_Emulation: Introduce notion of 'bts_role'

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6627

RSL_Emulation: Introduce notion of 'bts_role'

So far we assumed we emulate the BTS side and talk to a BSC.

Let's make this configurable and disable the BTS-side spcific code
paths by means of a 'bts_role' boolean type.

Change-Id: I0d0460cbb633b470f6117d07643f68aefb1530eb
---
M library/RSL_Emulation.ttcn
1 file changed, 20 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/27/6627/1

diff --git a/library/RSL_Emulation.ttcn b/library/RSL_Emulation.ttcn
index dab1785..5c7dc9c 100644
--- a/library/RSL_Emulation.ttcn
+++ b/library/RSL_Emulation.ttcn
@@ -52,6 +52,11 @@
inout RSLDC_ChanRqd, RSL_Message;
 } with { extension "internal" };
 
+type port RSL_CCHAN_PT message {
+   inout ASP_RSL_Unitdata;
+} with { extension "internal" };
+
+
 signature RSLEM_register(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr 
hdlr);
 signature RSLEM_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr 
hdlr);
 signature RSLEM_suspend(boolean suspend);
@@ -242,6 +247,9 @@
port RSL_DCHAN_PT CLIENT_PT;
port RSLEM_PROC_PT RSL_PROC;
 
+   /* port for Common Channel / TRX Management */
+   port RSL_CCHAN_PT CCHAN_PT;
+
/* state of all concurrent connections / dedicated channels */
var ConnectionData ConnectionTable[64];
 }
@@ -268,7 +276,7 @@
 }
 
 
-function main() runs on RSL_Emulation_CT {
+function main(boolean bts_role := true) runs on RSL_Emulation_CT {
var ASP_RSL_Unitdata rx_rsl;
var RSL_Message rx_rsl_msg;
var RSLDC_ChanRqd chan_rqd;
@@ -286,10 +294,10 @@
alt {
[] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) {
}
-   [] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_ID_ACK}) {
+   [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_ID_ACK}) {

IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
}
-   [] IPA_PT.receive(tr_RSL(tr_RSL_IMM_ASSIGN)) -> value rx_rsl {
+   [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_IMM_ASSIGN)) -> value 
rx_rsl {
var GsmRrMessage rr;
var OCT1 ra;
var GsmFrameNumber fn;
@@ -327,7 +335,7 @@
}
}
 
-   [] IPA_PT.receive(tr_RSL(tr_RSL_PAGING_CMD(?, ?))) -> value 
rx_rsl {
+   [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_PAGING_CMD(?, ?))) -> 
value rx_rsl {
log("PAGING IDENTITY ", rx_rsl.rsl.ies[2].body.other);
/* broadcast to all clients? */
for (i := 0; i < sizeof(ConnectionTable); i := i + 1) {
@@ -337,16 +345,20 @@
}
}
 
+   /* Forward common channel management to the special port for it 
*/
[] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeT(?))) -> value rx_rsl {
-   log("Ingnoring TRX Mgmt ", rx_rsl.rsl);
+   log("Forwarding TRX Mgmt ", rx_rsl.rsl);
+   CCHAN_PT.send(rx_rsl);
}
 
+   /* Forward common channel management to the special port for it 
*/
[] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeC(?))) -> value rx_rsl {
-   log("Ignoring Common Channel Mgmt ", rx_rsl.rsl);
+   log("Forwarding Common Channel Mgmt ", rx_rsl.rsl);
+   CCHAN_PT.send(rx_rsl);
}
 
/* blindly acknowledge all channel activations */
-   [] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) 
-> value rx_rsl {
+   [bts_role] 
IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) -> value rx_rsl {
chan_nr := rx_rsl.rsl.ies[0].body.chan_nr;
IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.streamId, 
ts_RSL_CHAN_ACT_ACK(chan_nr, 23)));
}
@@ -367,7 +379,7 @@
self.stop;
}
 
-   [] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender 
vc_conn {
+   [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd 
sender vc_conn {
/* Store the knowledge that this sender has requested a 
certain RQ+time */
f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn);
IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,

-- 
To view, visit https://gerrit.osmocom.org/6627
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d0460cbb633b470f6117d07643f68aefb1530eb
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 


osmo-trx[master]: Logger: get rid of alarm APIs

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6612
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I6d6df1578c3a4c1a37bd0d69952d443f62eed2ab
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: Logger: Remove unused logging macros

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6611
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I1133e181183bec8dabe2fa77d0385f783458503f
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: Logger: Drop unused gLogEarly

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6610
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I2c8f24fbf453e0a94d7a95c3df7cc75f0e4bd456
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: Logger: Remove unused includes

2018-02-21 Thread Harald Welte

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6615
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I4d26c0b4f36ee3c66ed1a9e2e9fa2fa8272da16d
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: Logger: Drop support to log into file

2018-02-21 Thread Harald Welte

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6614
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: If2c77c776823f595130edac963be953026049423
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: configure.ac: Check for pkg-config

2018-02-21 Thread Harald Welte

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6617
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I1a851181a99f2f35ea4ff1b38c7afe27a04e5f18
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: Logger: Remove gLogToConsole flag

2018-02-21 Thread Harald Welte

Patch Set 2:

(1 comment)

https://gerrit.osmocom.org/#/c/6616/2//COMMIT_MSG
Commit Message:

Line 9: No code is using it and we always lock to console anyways.
log?


-- 
To view, visit https://gerrit.osmocom.org/6616
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I5fde99c6af5a845e635b5d27abab855682071f14
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: Yes


osmo-trx[master]: Logger: Drop syslog support

2018-02-21 Thread Harald Welte

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6613
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I8282745ef0282d41599eaf94fe460a1d29b18e2a
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: Add initial support for logging, vty, ctrl

2018-02-21 Thread Harald Welte

Patch Set 4:

(4 comments)

https://gerrit.osmocom.org/#/c/6619/4//COMMIT_MSG
Commit Message:

Line 12: Depends on libosmocore Change-Id 
Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9
Related: OS#2184


https://gerrit.osmocom.org/#/c/6619/4/CommonLibs/debug.c
File CommonLibs/debug.c:

Line 9: .description = "Transciever",
_ei_ not _ie_ because its receiver, not reciever and "Transceiver" is from 
Transmitter + Receiver.


https://gerrit.osmocom.org/#/c/6619/4/CommonLibs/debug.h
File CommonLibs/debug.h:

Line 7: DTRX,
I'm honestly not sure if it makes sense to start a category with this name.  
The program is called "OsmoTRX/Trnsceiver", it implements one or multiple GSM 
TRXs, but then only the lower layers of it.  What exactly wold go in here?

I think it makes sense to straight ahead add meaningful categories for 
idividual code sub-sections.  And if you must add a global one, I would simply 
call it DMAIN or DGLOBAL or DMISC or whatever...


https://gerrit.osmocom.org/#/c/6619/4/CommonLibs/trx_vty.c
File CommonLibs/trx_vty.c:

Line 138:   "Copyright (C) 2013 Thomas Tsou \r\n"
I think this should state all major copyright holders. Doing some research on 
the Copyright statements in the source, there is:
* FSF
* Ettus
* Tom Tsou
* sysmocom

I guess we can leave out the folling names:
* Range (only GSMCommon.cpp that is *very* small, and Logger.cpp, which we will 
no longer use?)
* Kestrel (only in LogTest.cpp, which is not part of the binary program that 
prints the above message
* Alexander Chemersi (only copyright claim is in PRBSTest.cpp, whcih is also 
not part of the osmo-trx binary)


-- 
To view, visit https://gerrit.osmocom.org/6619
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-HasComments: Yes


osmo-trx[master]: Logger: Use libosmocore logging system

2018-02-21 Thread Harald Welte

Patch Set 4:

(1 comment)

https://gerrit.osmocom.org/#/c/6620/4/CommonLibs/Logger.cpp
File CommonLibs/Logger.cpp:

Line 2: * Copyright 2009, 2010 Free Software Foundation, Inc.
makes sense to update this copyright statement. Basically all the code is 
replaced/removed from this file right? then the old copyright should also be 
removed/replacd in the same commit


-- 
To view, visit https://gerrit.osmocom.org/6620
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I30baac89f53e927f8699d0586b43cccf88ecd493
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: Yes


[MERGED] osmo-trx[master]: Logger: get rid of alarm APIs

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Logger: get rid of alarm APIs
..


Logger: get rid of alarm APIs

It's only used internally inside the Logger module, and in case there's
an "alarm" (level more than critical) we still print on cerr, so we can
just rely on our system catching stderr instead of stdout to handle it.

Change-Id: I6d6df1578c3a4c1a37bd0d69952d443f62eed2ab
---
M CommonLibs/Logger.cpp
M CommonLibs/Logger.h
M tests/CommonLibs/LogTest.cpp
M tests/CommonLibs/LogTest.ok
4 files changed, 0 insertions(+), 97 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index ee607fd..4bfb782 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -35,8 +35,6 @@
 #include "Logger.h"
 #include "Threads.h"   // pat added
 
-#define MAX_ALARMS 20
-
 using namespace std;
 
 // Switches to enable/disable logging targets
@@ -47,26 +45,6 @@
 
 // Global log level threshold:
 int config_log_level;
-
-/**@ The global alarms table. */
-//@{
-Mutex   alarmsLock;
-listalarmsList;
-voidaddAlarm(const string&);
-//@}
-
-
-
-// (pat) If Log messages are printed before the classes in this module are 
inited
-// (which happens when static classes have constructors that do work)
-// the OpenBTS just crashes.
-// Prevent that by setting sLoggerInited to true when this module is inited.
-static bool sLoggerInited = 0;
-static struct CheckLoggerInitStatus {
-   CheckLoggerInitStatus() { sLoggerInited = 1; }
-} sCheckloggerInitStatus;
-
-
 
 /** Names of the logging levels. */
 const char *levelNames[] = {
@@ -119,36 +97,11 @@
return os << ss.str();
 }
 
-// copies the alarm list and returns it. list supposed to be small.
-list gGetLoggerAlarms()
-{
-alarmsLock.lock();
-list ret;
-// excuse the "complexity", but to use std::copy with a list you need
-// an insert_iterator - copy technically overwrites, doesn't insert.
-insert_iterator< list > ii(ret, ret.begin());
-copy(alarmsList.begin(), alarmsList.end(), ii);
-alarmsLock.unlock();
-return ret;
-}
-
-/** Add an alarm to the alarm list. */
-void addAlarm(const string& s)
-{
-alarmsLock.lock();
-alarmsList.push_back(s);
-while (alarmsList.size() > MAX_ALARMS) alarmsList.pop_front();
-alarmsLock.unlock();
-}
-
-
 Log::~Log()
 {
if (mDummyInit) return;
// Anything at or above LOG_CRIT is an "alarm".
-   // Save alarms in the local list and echo them to stderr.
if (mPriority <= LOG_ERR) {
-   if (sLoggerInited) addAlarm(mStream.str().c_str());
cerr << mStream.str() << endl;
}
// Current logging level was already checked by the macro. So just log.
diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index ef11932..7b208fa 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -103,10 +103,6 @@
 extern bool gLogToConsole; // Output log messages to stdout
 extern bool gLogToSyslog;  // Output log messages to syslog
 
-
-
-std::list gGetLoggerAlarms(); ///< Get a copy of the 
recent alarm list.
-
 const std::string timestr();   // A timestamp to print in messages.
 std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
 
diff --git a/tests/CommonLibs/LogTest.cpp b/tests/CommonLibs/LogTest.cpp
index f64041d..5d1dd2c 100644
--- a/tests/CommonLibs/LogTest.cpp
+++ b/tests/CommonLibs/LogTest.cpp
@@ -29,14 +29,6 @@
 
 #include "Logger.h"
 
-void printAlarms()
-{
-std::ostream_iterator output( std::cout, "\n" );
-std::list alarms = gGetLoggerAlarms();
-std::cout << "# alarms = " << alarms.size() << std::endl;
-std::copy( alarms.begin(), alarms.end(), output );
-}
-
 int main(int argc, char *argv[])
 {
gLogInit("LogTest","NOTICE",LOG_LOCAL7);
@@ -49,14 +41,8 @@
Log(LOG_NOTICE).get() << " testing the logger.";
Log(LOG_INFO).get() << " testing the logger.";
 Log(LOG_DEBUG).get() << " testing the logger.";
-std::cout << "\n\n\n";
-std::cout << "testing Alarms\n";
-std::cout << "you should see three lines:" << std::endl;
-printAlarms();
 std::cout << "--- generating 20 alarms --" << std::endl;
 for (int i = 0 ; i < 20 ; ++i) {
 Log(LOG_ALERT).get() << i;
 }
-std::cout << "you should see ten lines with the numbers 10..19:" << 
std::endl;
-printAlarms();
 }
diff --git a/tests/CommonLibs/LogTest.ok b/tests/CommonLibs/LogTest.ok
index e1211b0..ac60314 100644
--- a/tests/CommonLibs/LogTest.ok
+++ b/tests/CommonLibs/LogTest.ok
@@ -6,39 +6,7 @@
 NOTICE  testing the logger.
 INFO  testing the logger.
 DEBUG  testing the logger.
-
-
-
-testing Alarms
-you should see three lines:
-# alarms = 4
-EMERG  testing the logger.
-ALERT  testing the logger.
-CRIT  testing the logger.
-ERR  tes

[MERGED] osmo-trx[master]: Logger: Remove gLogToConsole flag

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Logger: Remove gLogToConsole flag
..


Logger: Remove gLogToConsole flag

No code is using it and we always lock to console anyways.

Change-Id: I5fde99c6af5a845e635b5d27abab855682071f14
---
M CommonLibs/Logger.cpp
M CommonLibs/Logger.h
2 files changed, 8 insertions(+), 15 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index b05e7fd..4c2a2d3 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -37,8 +37,6 @@
 
 using namespace std;
 
-// Switches to enable/disable logging targets
-bool gLogToConsole = true;
 Mutex gLogToLock;
 
 // Global log level threshold:
@@ -101,18 +99,14 @@
if (mPriority <= LOG_ERR) {
cerr << mStream.str() << endl;
}
-   // Log to file and console
-   if (gLogToConsole) {
-   int mlen = mStream.str().size();
-   int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');
-   ScopedLock lock(gLogToLock);
-   if (gLogToConsole) {
-   // The COUT() macro prevents messages from stomping 
each other but adds uninteresting thread numbers,
-   // so just use std::cout.
-   std::cout << mStream.str();
-   if (neednl) std::cout<<"\n";
-   }
-   }
+
+   int mlen = mStream.str().size();
+   int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');
+   ScopedLock lock(gLogToLock);
+   // The COUT() macro prevents messages from stomping each other but adds 
uninteresting thread numbers,
+   // so just use std::cout.
+   std::cout << mStream.str();
+   if (neednl) std::cout<<"\n";
 }
 
 ostringstream& Log::get()
diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index 32ee891..a8fe44d 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -88,7 +88,6 @@
 
std::ostringstream& get();
 };
-extern bool gLogToConsole; // Output log messages to stdout
 
 const std::string timestr();   // A timestamp to print in messages.
 std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);

-- 
To view, visit https://gerrit.osmocom.org/6616
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5fde99c6af5a845e635b5d27abab855682071f14
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


osmo-ttcn3-hacks[master]: IPA_Emulation: Don't log IPAC_MSGT_ID_RESP as "Unknown/unsup...

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6626
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I6ea3855a1f3d1cba6ac173b0f9cf9052d5d028fc
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[MERGED] osmo-trx[master]: Logger: Drop unused gLogEarly

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Logger: Drop unused gLogEarly
..


Logger: Drop unused gLogEarly

Change-Id: I2c8f24fbf453e0a94d7a95c3df7cc75f0e4bd456
---
M CommonLibs/Logger.cpp
M CommonLibs/Logger.h
2 files changed, 0 insertions(+), 35 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index 5b8da99..ee607fd 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -214,37 +214,4 @@
openlog(name,0,facility);
 }
 
-
-void gLogEarly(int level, const char *fmt, ...)
-{
-   va_list args;
-
-   va_start(args, fmt);
-
-   if (gLogToSyslog) {
-   va_list args_copy;
-   va_copy(args_copy, args);
-   vsyslog(level | LOG_USER, fmt, args_copy);
-   va_end(args_copy);
-   }
-
-   if (gLogToConsole) {
-   va_list args_copy;
-   va_copy(args_copy, args);
-   vprintf(fmt, args_copy);
-   printf("\n");
-   va_end(args_copy);
-   }
-
-   if (gLogToFile) {
-   va_list args_copy;
-   va_copy(args_copy, args);
-   vfprintf(gLogToFile, fmt, args_copy);
-   fprintf(gLogToFile, "\n");
-   va_end(args_copy);
-   }
-
-   va_end(args);
-}
-
 // vim: ts=4 sw=4
diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index 099d300..9743b88 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -131,8 +131,6 @@
 //@{
 /** Initialize the global logging system. */
 void gLogInit(const char* name, const char* level=NULL, int facility=LOG_USER, 
char* fn=NULL);
-/** Allow early logging when still in constructors */
-void gLogEarly(int level, const char *fmt, ...) __attribute__((format(printf, 
2, 3)));
 //@}
 
 

-- 
To view, visit https://gerrit.osmocom.org/6610
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2c8f24fbf453e0a94d7a95c3df7cc75f0e4bd456
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


osmo-ttcn3-hacks[master]: RSL_Emulation: Pass ASP_IPA_EVENT_UP to RSL_CCHAN port

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6628
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Iad2f6e4cb6a8f3b77e452f36a83ec11e7554e6c7
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-ttcn3-hacks[master]: RSL_Types: Add templates for "BSC side"

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6607
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ica9cfae5a691e4d967d046b04e5bb16a71a89adf
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[MERGED] osmo-trx[master]: Logger: Remove unused logging macros

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Logger: Remove unused logging macros
..


Logger: Remove unused logging macros

Change-Id: I1133e181183bec8dabe2fa77d0385f783458503f
---
M CommonLibs/Logger.h
1 file changed, 0 insertions(+), 17 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index 9743b88..ef11932 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -66,23 +66,6 @@
 // LOG_INFO6  informational message
 // LOG_DEBUG   7  debug-level message
 
-// (pat) added - print out a var and its name.
-// Use like this: int descriptive_name; LOG(INFO)

osmo-trx[master]: Logger: Remove gLogToConsole flag

2018-02-21 Thread Harald Welte

Patch Set 2: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6616
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I5fde99c6af5a845e635b5d27abab855682071f14
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-ttcn3-hacks[master]: IPA_Emulation: Make dependencies to RSL/MGCP/SCCP/GSUP condi...

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6608
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ic0231adbd2171214de133d26b3fbf36130ee8aa0
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[MERGED] osmo-trx[master]: Logger: Remove unused includes

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Logger: Remove unused includes
..


Logger: Remove unused includes

Change-Id: I4d26c0b4f36ee3c66ed1a9e2e9fa2fa8272da16d
---
M CommonLibs/Logger.h
1 file changed, 0 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.h b/CommonLibs/Logger.h
index e979284..32ee891 100644
--- a/CommonLibs/Logger.h
+++ b/CommonLibs/Logger.h
@@ -35,8 +35,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 
 extern int config_log_level;
@@ -63,8 +61,6 @@
 #define LOG(wLevel) \
if (IS_LOG_LEVEL(wLevel)) _LOG(wLevel)
 #endif
-
-#include "Threads.h"   // must be after defines above, if these files 
are to be allowed to use LOG()
 
 /**
A C++ stream-based thread-safe logger.

-- 
To view, visit https://gerrit.osmocom.org/6615
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4d26c0b4f36ee3c66ed1a9e2e9fa2fa8272da16d
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


osmo-ttcn3-hacks[master]: RSL_Emulation: Introduce notion of 'bts_role'

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6627
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I0d0460cbb633b470f6117d07643f68aefb1530eb
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[MERGED] osmo-trx[master]: Logger: Drop syslog support

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Logger: Drop syslog support
..


Logger: Drop syslog support

This feature is currently not being used, so let's drop it to make it
easier to integrate into libosmocore logging system in the future.

Change-Id: I8282745ef0282d41599eaf94fe460a1d29b18e2a
---
M CommonLibs/Logger.cpp
M CommonLibs/Logger.h
M INSTALLATION
M Transceiver52M/osmo-trx.cpp
M tests/CommonLibs/LogTest.cpp
5 files changed, 14 insertions(+), 47 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index 4bfb782..2cdd158 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -39,7 +39,6 @@
 
 // Switches to enable/disable logging targets
 bool gLogToConsole = true;
-bool gLogToSyslog = false;
 FILE *gLogToFile = NULL;
 Mutex gLogToLock;
 
@@ -99,15 +98,9 @@
 
 Log::~Log()
 {
-   if (mDummyInit) return;
// Anything at or above LOG_CRIT is an "alarm".
if (mPriority <= LOG_ERR) {
cerr << mStream.str() << endl;
-   }
-   // Current logging level was already checked by the macro. So just log.
-   // Log to syslog
-   if (gLogToSyslog) {
-   syslog(mPriority, "%s", mStream.str().c_str());
}
// Log to file and console
if (gLogToConsole||gLogToFile) {
@@ -128,14 +121,6 @@
}
 }
 
-
-Log::Log(const char* name, const char* level, int facility)
-{
-   mDummyInit = true;
-   gLogInit(name, level, facility);
-}
-
-
 ostringstream& Log::get()
 {
assert(mPriority
 #include 
 #include 
 #include 
@@ -41,6 +40,15 @@
 #include 
 
 extern int config_log_level;
+
+#define LOG_EMERG   0   /* system is unusable */
+#define LOG_ALERT   1   /* action must be taken immediately */
+#define LOG_CRIT2   /* critical conditions */
+#define LOG_ERR 3   /* error conditions */
+#define LOG_WARNING 4   /* warning conditions */
+#define LOG_NOTICE  5   /* normal but significant condition */
+#define LOG_INFO6   /* informational */
+#define LOG_DEBUG   7   /* debug-level messages */
 
 #define _LOG(level) \
Log(LOG_##level).get() << pthread_self() \
@@ -56,23 +64,10 @@
if (IS_LOG_LEVEL(wLevel)) _LOG(wLevel)
 #endif
 
-// pat: And for your edification here are the 'levels' as defined in syslog.h:
-// LOG_EMERG   0  system is unusable
-// LOG_ALERT   1  action must be taken immediately
-// LOG_CRIT2  critical conditions
-// LOG_ERR 3  error conditions
-// LOG_WARNING 4  warning conditions
-// LOG_NOTICE  5  normal, but significant, condition
-// LOG_INFO6  informational message
-// LOG_DEBUG   7  debug-level message
-
-
 #include "Threads.h"   // must be after defines above, if these files 
are to be allowed to use LOG()
 
 /**
A C++ stream-based thread-safe logger.
-   Derived from Dr. Dobb's Sept. 2007 issue.
-   Updated to use syslog.
This object is NOT the global logger;
every log record is an object of this class.
 */
@@ -84,15 +79,12 @@
 
std::ostringstream mStream; ///< This is where we buffer up 
the log entry.
int mPriority;  ///< Priority of 
current report.
-   bool mDummyInit;
 
public:
 
Log(int wPriority)
-   :mPriority(wPriority), mDummyInit(false)
+   :mPriority(wPriority)
{ }
-
-   Log(const char* name, const char* level=NULL, int facility=LOG_USER);
 
// Most of the work is in the destructor.
/** The destructor actually generates the log entry. */
@@ -101,7 +93,6 @@
std::ostringstream& get();
 };
 extern bool gLogToConsole; // Output log messages to stdout
-extern bool gLogToSyslog;  // Output log messages to syslog
 
 const std::string timestr();   // A timestamp to print in messages.
 std::ostream& operator<<(std::ostream& os, std::ostringstream& ss);
@@ -109,7 +100,7 @@
 /**@ Global control and initialization of the logging system. */
 //@{
 /** Initialize the global logging system. */
-void gLogInit(const char* name, const char* level=NULL, int facility=LOG_USER, 
char* fn=NULL);
+void gLogInit(const char* level=NULL, char* fn=NULL);
 //@}
 
 
diff --git a/INSTALLATION b/INSTALLATION
index 0c0d205..f87b6cc 100644
--- a/INSTALLATION
+++ b/INSTALLATION
@@ -12,14 +12,8 @@
libuhd (https://gnuradio.org).
This is part of the GNURadio installation.
 
-
-osmo-trx logs to syslogd as facility LOG_LOCAL7.  Please set your 
/etc/syslog.conf
-accordingly.
-
-
 For information on specific executables, see tests/README.tests and
 apps/README.apps.
 
 See https://osmocom.org/projects/osmotrx/wiki/OsmoTRX for more
 information.
-
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp

[MERGED] osmo-trx[master]: Logger: Drop support to log into file

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Logger: Drop support to log into file
..


Logger: Drop support to log into file

This feature is currently not being used, so let's simplify current code
to move to libosmocore logging system in the future.

Change-Id: If2c77c776823f595130edac963be953026049423
---
M CommonLibs/Logger.cpp
1 file changed, 1 insertion(+), 19 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index 2cdd158..b05e7fd 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -39,7 +39,6 @@
 
 // Switches to enable/disable logging targets
 bool gLogToConsole = true;
-FILE *gLogToFile = NULL;
 Mutex gLogToLock;
 
 // Global log level threshold:
@@ -103,7 +102,7 @@
cerr << mStream.str() << endl;
}
// Log to file and console
-   if (gLogToConsole||gLogToFile) {
+   if (gLogToConsole) {
int mlen = mStream.str().size();
int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');
ScopedLock lock(gLogToLock);
@@ -112,11 +111,6 @@
// so just use std::cout.
std::cout << mStream.str();
if (neednl) std::cout<<"\n";
-   }
-   if (gLogToFile) {
-   fputs(mStream.str().c_str(),gLogToFile);
-   if (neednl) {fputc('\n',gLogToFile);}
-   fflush(gLogToFile);
}
}
 }
@@ -135,18 +129,6 @@
// Set the level if one has been specified.
if (level)
config_log_level = levelStringToInt(level);
-
-   // Both the transceiver and OpenBTS use this same facility, but only 
OpenBTS/OpenNodeB may use this log file:
-   if (!gLogToFile && fn) {
-   gLogToFile = fopen(fn,"w"); // New log file each time we start.
-   if (gLogToFile) {
-   time_t now;
-   time(&now);
-   fprintf(gLogToFile,"Starting at %s",ctime(&now));
-   fflush(gLogToFile);
-   std::cout << "Logging to file: " << fn << "\n";
-   }
-   }
 }
 
 // vim: ts=4 sw=4

-- 
To view, visit https://gerrit.osmocom.org/6614
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If2c77c776823f595130edac963be953026049423
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


osmo-sip-connector[master]: contrib: jenkins.sh: Disable doxygen in libosmocore build

2018-02-21 Thread Harald Welte

Patch Set 1:

commitlog is missing the important part on "why" (I know, but the commit log is 
for everyone to read/understand)

-- 
To view, visit https://gerrit.osmocom.org/6625
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I7befa0cb4e72a6ad086e3c2d290546dbf22f1676
Gerrit-PatchSet: 1
Gerrit-Project: osmo-sip-connector
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-iuh[master]: contrib: jenkins.sh: Disable doxygen in libosmocore build

2018-02-21 Thread Harald Welte

Patch Set 1:

commitlog is missing the important part on "why" (I know, but the commit log is 
for everyone to read/understand)

-- 
To view, visit https://gerrit.osmocom.org/6624
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I12d995c0c993483ed940fc173904d6e686fbe0ab
Gerrit-PatchSet: 1
Gerrit-Project: osmo-iuh
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


libosmo-abis[master]: contrib: jenkins.sh: Disable doxygen in libosmocore build

2018-02-21 Thread Harald Welte

Patch Set 1:

commitlog is missing the important part on "why" (I know, but the commit log is 
for everyone to read/understand)

-- 
To view, visit https://gerrit.osmocom.org/6622
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I52fc3931ef072075561858bb7173f58a8503e499
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


libosmocore[master]: ports.h: Add VTY and CTRL ports for osmo-trx

2018-02-21 Thread Harald Welte

Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/6623/1/include/osmocom/vty/ports.h
File include/osmocom/vty/ports.h:

Line 34: #define OSMO_VTY_PORT_TRX  4263
I would argue for a lower port number. Trdaitionally we've had lower port 
numbers for lower elements in the stack (i.e. BTS < BSC < MSC < HLR). So I 
would go for numbers below 2439 if possible, putting it closer to PCU+BTS.


-- 
To view, visit https://gerrit.osmocom.org/6623
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: Yes


osmo-pcu[master]: TBF: make network counters internal

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6609
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I89c7186f74bde7e6ac5f6e98f0b3e4c35274
Gerrit-PatchSet: 1
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[MERGED] osmo-pcu[master]: TBF: make network counters internal

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: TBF: make network counters internal
..


TBF: make network counters internal

* store N310* counters in shared array similar to corresponding timers
* add functions to increment/reset counters

This avoids direct access to TBF counters from PDCH.

Change-Id: I89c7186f74bde7e6ac5f6e98f0b3e4c35274
Related: OS#1539
---
M src/pdch.cpp
M src/tbf.cpp
M src/tbf.h
M src/tbf_dl.cpp
M src/tbf_ul.cpp
5 files changed, 88 insertions(+), 35 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/pdch.cpp b/src/pdch.cpp
index ee9df31..22a1605 100644
--- a/src/pdch.cpp
+++ b/src/pdch.cpp
@@ -290,7 +290,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
tbf->update_ms(tlli, GPRS_RLCMAC_UL_TBF);
 
@@ -310,7 +310,7 @@
if (tbf->dl_ass_state_is(GPRS_RLCMAC_DL_ASS_WAIT_ACK)) {
LOGPTBF(tbf, LOGL_DEBUG, "[UPLINK] DOWNLINK ASSIGNED\n");
/* reset N3105 */
-   tbf->n3105 = 0;
+   tbf->n_reset(N3105);
TBF_SET_ASS_STATE_DL(tbf, GPRS_RLCMAC_DL_ASS_NONE);
 
new_tbf = tbf->ms() ? tbf->ms()->dl_tbf() : NULL;
@@ -342,7 +342,7 @@
if (tbf->ul_ass_state_is(GPRS_RLCMAC_UL_ASS_WAIT_ACK)) {
LOGPTBF(tbf, LOGL_DEBUG, "[DOWNLINK] UPLINK ASSIGNED\n");
/* reset N3105 */
-   tbf->n3105 = 0;
+   tbf->n_reset(N3105);
TBF_SET_ASS_STATE_UL(tbf, GPRS_RLCMAC_UL_ASS_NONE);
 
new_tbf = tbf->ms() ? tbf->ms()->ul_tbf() : NULL;
@@ -399,7 +399,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
if (tbf->handle_ack_nack())
LOGPTBF(tbf, LOGL_NOTICE, "Recovered downlink ack\n");
@@ -466,7 +466,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
if (tbf->handle_ack_nack())
LOGPTBF(tbf, LOGL_NOTICE, "Recovered EGPRS downlink ack\n");
@@ -638,7 +638,7 @@
"RX: [PCU <- BTS] FIXME: Packet resource request\n");
 
/* Reset N3101 counter: */
-   dl_tbf->m_n3101 = 0;
+   dl_tbf->n_reset(N3101);
} else {
struct gprs_rlcmac_ul_tbf *ul_tbf;
int8_t tfi = request->ID.u.Global_TFI.u.UPLINK_TFI;
@@ -651,7 +651,7 @@
"RX: [PCU <- BTS] FIXME: Packet resource request\n");
 
/* Reset N3101 counter: */
-   ul_tbf->m_n3101 = 0;
+   ul_tbf->n_reset(N3101);
}
 }
 
@@ -806,7 +806,7 @@
}
 
/* Reset N3101 counter: */
-   tbf->m_n3101 = 0;
+   tbf->n_reset(N3101);
 
return tbf->rcv_data_block_acknowledged(&rlc_dec, data, meas);
 }
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 72b39ec..7036ea1 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -80,6 +80,13 @@
{ 0, NULL }
 };
 
+static const struct value_string tbf_counters_names[] = {
+   OSMO_VALUE_STRING(N3101),
+   OSMO_VALUE_STRING(N3103),
+   OSMO_VALUE_STRING(N3105),
+   { 0, NULL }
+};
+
 static const struct value_string tbf_timers_names[] = {
OSMO_VALUE_STRING(T0),
OSMO_VALUE_STRING(T3169),
@@ -187,13 +194,11 @@
control_ts(0xff),
poll_fn(0),
poll_ts(0),
-   n3105(0),
fT(0),
num_fT_exp(0),
was_releasing(0),
upgrade_to_multislot(0),
bts(bts_),
-   m_n3101(0),
m_tfi(0),
m_created_ts(0),
m_ctrs(NULL),
@@ -213,6 +218,7 @@
 * Just set them to 0 like talloc_zero did */
memset(&pdch, 0, sizeof(pdch));
memset(&T, 0, sizeof(T));
+   memset(&N, 0, sizeof(N));
memset(&m_rlc, 0, sizeof(m_rlc));
memset(&gsm_timer, 0, sizeof(gsm_timer));
 
@@ -546,6 +552,55 @@
"RELEASING",
 };
 
+void gprs_rlcmac_tbf::n_reset(enum tbf_counters n)
+{
+   if (n >= N_MAX) {
+   LOGPTBF(this, LOGL_ERROR, "attempting to reset unknown counter 
%s\n",
+   get_value_string(tbf_counters_names, n));
+   return;
+   }
+
+   N[n] = 0;
+}
+
+/* Increment counter and check for MAX value (return true if we hit it) */
+bool gprs_rlcmac_tbf::n_inc(enum tbf_counters n)
+{
+   uint8_t chk;
+
+   if (n >= N_MAX) {
+   LOGPTBF(this, LOGL_ERROR, "attempting to increment unknown 
counter %s\n",
+   get_value_string(tbf_counters_names, n));
+   return true;
+   }
+
+   N[n]++;
+
+   switch(n) {
+   case N3101:
+   chk = bts->bts_data()->n3101;
+   break;
+   case N3103:
+   chk = bts->bts_data()->n3103;
+   break;
+   c

osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-02-21 Thread Harald Welte

Patch Set 17: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/3905
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Gerrit-PatchSet: 17
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Holger Freyther 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-pcu[master]: TS alloc: expand tests log

2018-02-21 Thread Harald Welte

Patch Set 27:

(1 comment)

https://gerrit.osmocom.org/#/c/3895/27/tests/alloc/AllocTest.err
File tests/alloc/AllocTest.err:

Line 196: [DL] algo A  (suggested TRX: -1): failed to find a usable TRX 
(TFI exhausted)
why does the old log line statte "multi" and the new one "single"? This looks 
suspicious. I thought only the logging is changed in this patch, not the actual 
logic?


-- 
To view, visit https://gerrit.osmocom.org/3895
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I4b78951a79ddbc0745b39d091080a4e0e247d3c5
Gerrit-PatchSet: 27
Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Owner: Max 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max 
Gerrit-HasComments: Yes


[MERGED] osmo-pcu[master]: Simplify TS alloc: move slot check into functions

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Simplify TS alloc: move slot check into functions
..


Simplify TS alloc: move slot check into functions

Move timeslot applicability check outside of nested for loop into
separate functions and document them. Add corresponding tests.

This allows us to clarify types used in TS-related computations.

Change-Id: Ic39e848da47dc11357782362fdf6206d2c1457c2
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
M src/mslot_class.c
M src/mslot_class.h
M tests/alloc/MslotTest.cpp
M tests/alloc/MslotTest.ok
5 files changed, 626 insertions(+), 123 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index 4cc9539..835c199 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -54,19 +54,11 @@
return buf;
 }
 
-static bool test_and_set_bit(uint32_t *bits, size_t elem)
-{
-   bool was_set = bits[elem/32] & (1 << (elem % 32));
-   bits[elem/32] |= (1 << (elem % 32));
-
-   return was_set;
-}
-
-static int find_possible_pdchs(const struct gprs_rlcmac_trx *trx, size_t 
max_slots, uint8_t mask,
-  const char *mask_reason = NULL)
+static uint8_t find_possible_pdchs(const struct gprs_rlcmac_trx *trx, uint8_t 
max_slots, uint8_t mask,
+  const char *mask_reason = NULL)
 {
unsigned ts;
-   int valid_ts_set = 0;
+   uint8_t valid_ts_set = 0;
int8_t last_tsc = -1; /* must be signed */
 
for (ts = 0; ts < ARRAY_SIZE(trx->pdch); ts++) {
@@ -353,7 +345,7 @@
int trx_no;
int tfi = -1;
int usf = -1;
-   int mask = 0xff;
+   uint8_t mask = 0xff;
const char *mask_reason = NULL;
const GprsMs *ms = ms_;
const gprs_rlcmac_tbf *tbf = tbf_;
@@ -457,6 +449,58 @@
return capacity;
 }
 
+/*! Decide if a given slot should be skipped by multislot allocator
+ *
+ *  \param[in] ms_class Pointer to MS Class object
+ *  \param[in] check_tr Flag indicating whether we should check for Tra or Tta 
parameters for a given MS class
+ *  \param[in] rx_window Receive window
+ *  \param[in] tx_window Transmit window
+ *  \param[in,out] checked_rx array with already checked RX timeslots
+ *  \returns true if the slot should be skipped, false otherwise
+ */
+static bool skip_slot(uint8_t mslot_class, bool check_tr,
+ int16_t rx_window, int16_t tx_window,
+ uint32_t *checked_rx)
+{
+   uint8_t common_slot_count, req_common_slots,
+   rx_slot_count = pcu_bitcount(rx_window),
+   tx_slot_count = pcu_bitcount(tx_window);
+
+   /* Check compliance with TS 45.002, table 6.4.2.2.1 */
+   /* Whether to skip this round doesn not only depend on the bit
+* sets but also on check_tr. Therefore this check must be done
+* before doing the mslot_test_and_set_bit shortcut. */
+   if (mslot_class_get_type(mslot_class) == 1) {
+   uint16_t slot_sum = rx_slot_count + tx_slot_count;
+   /* Assume down + up / dynamic.
+* TODO: For ext-dynamic, down only, up only add more cases.
+*/
+   if (slot_sum <= 6 && tx_slot_count < 3) {
+   if (!check_tr)
+   return true; /* Skip Tta */
+   } else if (slot_sum > 6 && tx_slot_count < 3) {
+   if (check_tr)
+   return true; /* Skip Tra */
+   } else
+   return true; /* No supported row in TS 45.002, table 
6.4.2.2.1. */
+   }
+
+   /* Avoid repeated RX combination check */
+   if (mslot_test_and_set_bit(checked_rx, rx_window))
+   return true;
+
+   /* Check number of common slots according to TS 45.002, ยง6.4.2.2 */
+   common_slot_count = pcu_bitcount(tx_window & rx_window);
+   req_common_slots = OSMO_MIN(tx_slot_count, rx_slot_count);
+   if (mslot_class_get_type(mslot_class) == 1)
+   req_common_slots = OSMO_MIN(req_common_slots, 2);
+
+   if (req_common_slots != common_slot_count)
+   return true;
+
+   return false;
+}
+
 /*! Find set of slots available for allocation while taking MS class into 
account
  *
  *  \param[in] trx Pointer to TRX object
@@ -468,16 +512,12 @@
 int find_multi_slots(struct gprs_rlcmac_trx *trx, uint8_t mslot_class, uint8_t 
*ul_slots, uint8_t *dl_slots)
 {
uint8_t Tx = mslot_class_get_tx(mslot_class),   /* Max number of Tx 
slots */
-   Sum = mslot_class_get_sum(mslot_class); /* Max number of Tx + 
Rx slots */
-   int rx_window, tx_window, pdch_slots;
+   Sum = mslot_class_get_sum(mslot_class), /* Max number of Tx + 
Rx slots */
+   max_slots, 

[MERGED] osmo-pcu[master]: Simplify TS alloc: move slot assignment

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: Simplify TS alloc: move slot assignment
..


Simplify TS alloc: move slot assignment

Move into separate functions:
* move timeslot reservation
* move UL timeslot assignment
* move DL timeslot assignment

Change-Id: I64cf78c5cfc78664766f9769dd5cde632dab92b0
Related: OS#2282
---
M src/gprs_rlcmac_ts_alloc.cpp
M src/mslot_class.c
M src/mslot_class.h
M tests/tbf/TbfTest.err
4 files changed, 84 insertions(+), 42 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/gprs_rlcmac_ts_alloc.cpp b/src/gprs_rlcmac_ts_alloc.cpp
index f26b27c..4cc9539 100644
--- a/src/gprs_rlcmac_ts_alloc.cpp
+++ b/src/gprs_rlcmac_ts_alloc.cpp
@@ -812,6 +812,75 @@
return ul_slots;
 }
 
+/*! Update MS' reserved timeslots
+ *
+ *  \param[in,out] trx Pointer to TRX struct
+ *  \param[in,out] ms_ Pointer to MS object
+ *  \param[in] tbf_ Pointer to TBF struct
+ *  \param[in] res_ul_slots Newly reserved UL slots
+ *  \param[in] res_dl_slots Newly reserved DL slots
+ *  \param[in] ul_slots available UL slots (for logging only)
+ *  \param[in] dl_slots available DL slots (for logging only)
+ */
+static void update_ms_reserved_slots(gprs_rlcmac_trx *trx, GprsMs *ms, uint8_t 
res_ul_slots, uint8_t res_dl_slots,
+uint8_t ul_slots, uint8_t dl_slots)
+{
+   char slot_info[9] = { 0 };
+
+   if (res_ul_slots == ms->reserved_ul_slots() && res_dl_slots == 
ms->reserved_dl_slots())
+   return;
+
+   /* The reserved slots have changed, update the MS */
+   ms->set_reserved_slots(trx, res_ul_slots, res_dl_slots);
+
+   ts_format(slot_info, dl_slots, ul_slots);
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Reserved DL/UL slots: 
(TS=0)\"%s\"(TS=7)\n", slot_info);
+}
+
+/*! Assign given UL timeslots to UL TBF
+ *
+ *  \param[in,out] ul_tbf Pointer to UL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ *  \param[in] usf selected USF
+ */
+static void assign_ul_tbf_slots(struct gprs_rlcmac_ul_tbf *ul_tbf, 
gprs_rlcmac_trx *trx, uint8_t ul_slots, int tfi,
+   int *usf)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(ul_slots & (1 << ts)))
+   continue;
+
+   OSMO_ASSERT(usf[ts] >= 0);
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning UL TS %u\n", ts);
+   assign_uplink_tbf_usf(&trx->pdch[ts], ul_tbf, tfi, usf[ts]);
+   }
+}
+
+/*! Assign given DL timeslots to DL TBF
+ *
+ *  \param[in,out] dl_tbf Pointer to DL TBF struct
+ *  \param[in,out] trx Pointer to TRX object
+ *  \param[in] ul_slots Set of slots to be assigned
+ *  \param[in] tfi selected TFI
+ */
+static void assign_dl_tbf_slots(struct gprs_rlcmac_dl_tbf *dl_tbf, 
gprs_rlcmac_trx *trx, uint8_t dl_slots, int tfi)
+{
+   uint8_t ts;
+
+   for (ts = 0; ts < 8; ts++) {
+   if (!(dl_slots & (1 << ts)))
+   continue;
+
+   LOGP(DRLCMAC, LOGL_DEBUG, "- Assigning DL TS %u\n", ts);
+   assign_dlink_tbf(&trx->pdch[ts], dl_tbf, tfi);
+   }
+}
+
 /*! Slot Allocation: Algorithm B
  *
  * Assign as many downlink slots as possible.
@@ -834,8 +903,6 @@
int8_t first_common_ts;
uint8_t slotcount = 0;
uint8_t avail_count = 0, trx_no;
-   char slot_info[9] = {0};
-   int ts;
int first_ts = -1;
int usf[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
int rc;
@@ -927,50 +994,16 @@
 
/* Step 4: Update MS and TBF and really allocate the resources */
 
-   /* The reserved slots have changed, update the MS */
-   if (reserved_ul_slots != ms->reserved_ul_slots() ||
-   reserved_dl_slots != ms->reserved_dl_slots())
-   {
-   ms_->set_reserved_slots(trx,
-   reserved_ul_slots, reserved_dl_slots);
-
-   LOGP(DRLCMAC, LOGL_DEBUG,
-   "- Reserved DL/UL slots: (TS=0)\"%s\"(TS=7)\n",
-   set_flag_chars(set_flag_chars(set_flag_chars(slot_info,
-   dl_slots, 'D', '.'),
-   ul_slots, 'U'),
-   ul_slots & dl_slots, 'C'));
-   }
+   update_ms_reserved_slots(trx, ms_, reserved_ul_slots, 
reserved_dl_slots, ul_slots, dl_slots);
 
tbf_->trx = trx;
tbf_->first_common_ts = first_common_ts;
tbf_->first_ts = first_ts;
 
-   if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
-   struct gprs_rlcmac_dl_tbf *dl_tbf = as_dl_tbf(tbf_);
-   for (ts = 0; ts < 8; ts++) {
-   if (!(dl_slots & (1 << ts)))
-   continue;
-
-   LOGP(DRLCMAC, LOGL_DEBUG, "

[MERGED] osmo-trx[master]: configure.ac: Check for pkg-config

2018-02-21 Thread Pau Espin Pedrol
Pau Espin Pedrol has submitted this change and it was merged.

Change subject: configure.ac: Check for pkg-config
..


configure.ac: Check for pkg-config

Change-Id: I1a851181a99f2f35ea4ff1b38c7afe27a04e5f18
---
M configure.ac
1 file changed, 7 insertions(+), 0 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/configure.ac b/configure.ac
index 7d26ced..5c034e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,6 +49,13 @@
 AC_PROG_INSTALL
 AC_PATH_PROG([RM_PROG], [rm])
 
+dnl check for pkg-config (explained in detail in libosmocore/configure.ac)
+AC_PATH_PROG(PKG_CONFIG_INSTALLED, pkg-config, no)
+if test "x$PKG_CONFIG_INSTALLED" = "xno"; then
+AC_MSG_WARN([You need to install pkg-config])
+fi
+PKG_PROG_PKG_CONFIG([0.20])
+
 AC_LIBTOOL_WIN32_DLL
 AC_ENABLE_SHARED   dnl do build shared libraries
 AC_DISABLE_STATIC  dnl don't build static libraries

-- 
To view, visit https://gerrit.osmocom.org/6617
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1a851181a99f2f35ea4ff1b38c7afe27a04e5f18
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 


[PATCH] osmo-bsc[master]: HO: fix minor issues found by coverity

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6630

HO: fix minor issues found by coverity

handover_decision_2:
- lchan->conn should never be NULL, but if it is, don't crash in LOGPHO*
  macros.
- make certain to avoid modulo-zero. It's cosmetic since that config item is
  not allowed to be zero.

handover_test:
- check return value of gsm_generate_si().
- safer evaluation of main()'s argv.

Fixes: CID#182929, CID#182928, CID#182927, CID#182926
Change-Id: I68e8ed3a1e8659edb47ac3e8a10508f17a3f5670
---
M src/libbsc/handover_decision_2.c
M tests/handover/handover_test.c
2 files changed, 21 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/30/6630/1

diff --git a/src/libbsc/handover_decision_2.c b/src/libbsc/handover_decision_2.c
index 752b0d5..0135020 100644
--- a/src/libbsc/handover_decision_2.c
+++ b/src/libbsc/handover_decision_2.c
@@ -46,7 +46,7 @@
 lchan->ts->nr, \
 lchan->nr, \
 gsm_pchan_name(lchan->ts->pchan), \
-bsc_subscr_name(lchan->conn->bsub), \
+bsc_subscr_name(lchan->conn? lchan->conn->bsub : NULL), \
 ## args)
 
 #define LOGPHOLCHANTOBTS(lchan, new_bts, level, fmt, args...) \
@@ -57,7 +57,7 @@
 lchan->nr, \
 gsm_pchan_name(lchan->ts->pchan), \
 new_bts->nr, \
-bsc_subscr_name(lchan->conn->bsub), \
+bsc_subscr_name(lchan->conn? lchan->conn->bsub : NULL), \
 ## args)
 
 #define REQUIREMENT_A_TCHF 0x01
@@ -1114,6 +1114,7 @@
struct gsm_lchan *lchan = mr->lchan;
struct gsm_bts *bts = lchan->ts->trx->bts;
int av_rxlev = -EINVAL, av_rxqual = -EINVAL;
+   unsigned int pwr_interval;
 
/* we currently only do handover for TCH channels */
switch (mr->lchan->type) {
@@ -1234,8 +1235,12 @@
return;
}
 
+   /* pwr_interval's range is 1-99, clarifying that no div-zero shall 
happen in modulo below: */
+   pwr_interval = ho_get_hodec2_pwr_interval(bts->ho);
+   OSMO_ASSERT(pwr_interval);
+
/* try handover to a better cell */
-   if (av_rxlev >= 0 && (mr->nr % ho_get_hodec2_pwr_interval(bts->ho)) == 
0) {
+   if (av_rxlev >= 0 && (mr->nr % pwr_interval) == 0) {
LOGPHOLCHAN(lchan, LOGL_INFO, "Looking whether a cell has 
better RXLEV\n");
global_ho_reason = HO_REASON_BETTER_CELL;
find_alternative_lchan(lchan, false);
diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c
index e8716f2..d1f75ba 100644
--- a/tests/handover/handover_test.c
+++ b/tests/handover/handover_test.c
@@ -1223,7 +1223,6 @@
test_case_26,
test_case_27,
test_case_28,
-   NULL
 };
 
 static const struct log_info_cat log_categories[] = {
@@ -1269,21 +1268,21 @@
int bts_num = 0;
struct gsm_lchan *lchan[256];
int lchan_num = 0;
-   int test_count = 0;
int i;
int algorithm;
struct bsc_api bsc_api = {};
+   int test_case_i;
+   int last_test_i;
 
-   for (i = 0; test_cases[i]; i++)
-   test_count++;
+   test_case_i = argc > 1? atoi(argv[1]) : -1;
+   last_test_i = ARRAY_SIZE(test_cases) - 1;
 
-   if (argc <= 1 || atoi(argv[1]) >= test_count) {
-   for (i = 0; test_cases[i]; i++) {
+   if (test_case_i < 0 || test_case_i > last_test_i) {
+   for (i = 0; i <= last_test_i; i++) {
printf("Test #%d (algorithm %s):\n%s\n", i,
test_cases[i][0], test_cases[i][1]);
}
-   printf("\nPlease specify test case number 0..%d\n",
-   test_count - 1);
+   printf("\nPlease specify test case number 0..%d\n", 
last_test_i);
return EXIT_FAILURE;
}
 
@@ -1320,11 +1319,11 @@
 
bts_model_sysmobts_init();
 
-   test_case = test_cases[atoi(argv[1])];
+   test_case = test_cases[test_case_i];
 
fprintf(stderr, "\n");
fprintf(stderr, "Performing the following test %d (algorithm %s):\n%s",
-   atoi(argv[1]), test_case[0], test_case[1]);
+   test_case_i, test_case[0], test_case[1]);
algorithm = atoi(test_case[0]);
test_case += 2;
fprintf(stderr, "\n");
@@ -1343,9 +1342,10 @@
"TS(1-4) are TCH/F, TS(5-6) are TCH/H)\n", n);
for (i = 0; i < n; i++)
bts[bts_num + i] = create_bts(arfcn++);
-   for (i = 0; i < n; i++)
-   gsm_generate_si(bts[bts_num + i],
-   SYSINFO_TYPE_2);
+   for (i = 0; i < n; i++) {
+   if (gsm_generate_si(bts[bts_num + i], 
SYSINFO_TYPE_2))
+   fprintf(stderr, "Error ge

[PATCH] osmo-mgw[master]: compiler warning: ignore deprecated in mgcp_client_test.c

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6631

compiler warning: ignore deprecated in mgcp_client_test.c

mgcp_msg_crcx() causes deprecation warning, but it's fine for a unit test
to use deprecated API.

Change-Id: Iba6d0c9c729367e00a9ab7fff7c89007d336e59d
---
M tests/mgcp_client/mgcp_client_test.c
1 file changed, 2 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/31/6631/1

diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index ef2fca8..68b97ae 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -18,6 +18,8 @@
  * along with this program.  If not, see .
  */
 
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
 #include 
 
 #include 

-- 
To view, visit https://gerrit.osmocom.org/6631
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba6d0c9c729367e00a9ab7fff7c89007d336e59d
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] libosmocore[master]: ports.h: Add VTY and CTRL ports for osmo-trx

2018-02-21 Thread Pau Espin Pedrol
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6623

to look at the new patch set (#2).

ports.h: Add VTY and CTRL ports for osmo-trx

Change-Id: Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9
---
M include/osmocom/ctrl/ports.h
M include/osmocom/vty/ports.h
2 files changed, 5 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/23/6623/2

diff --git a/include/osmocom/ctrl/ports.h b/include/osmocom/ctrl/ports.h
index 4e93190..d6b5394 100644
--- a/include/osmocom/ctrl/ports.h
+++ b/include/osmocom/ctrl/ports.h
@@ -8,6 +8,9 @@
 
 #pragma once
 
+
+#define OSMO_CTRL_PORT_TRX 4236
+/* 4237 used by VTY interface */
 #define OSMO_CTRL_PORT_BTS 4238
 #define OSMO_CTRL_PORT_NITB_BSC4249
 #define OSMO_CTRL_PORT_BSC_NAT 4250
diff --git a/include/osmocom/vty/ports.h b/include/osmocom/vty/ports.h
index 4819b87..5e7e655 100644
--- a/include/osmocom/vty/ports.h
+++ b/include/osmocom/vty/ports.h
@@ -8,6 +8,8 @@
 
 #pragma once
 
+/* 4236 used by control interface */
+#define OSMO_VTY_PORT_TRX  4237
 /* 4238 used by osmo-bts control interface */
 #define OSMO_VTY_PORT_STP  4239
 #define OSMO_VTY_PORT_PCU  4240/* also: osmo_pcap_client */

-- 
To view, visit https://gerrit.osmocom.org/6623
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


[PATCH] osmo-bts[master]: RSL: Properly reject RSL CHAN_NR IE for incompatible PCHAN

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6634

RSL: Properly reject RSL CHAN_NR IE for incompatible PCHAN

If we receive a message for a dedicated channel, whose channel number
structure doesn't match with the physical channel (timeslot) type,
we must properly reject this.  For RSL CHAN ACT it means sending a NACK,
and for all other cases it means sending an RSL ERROR REPORT.

Related: OS#2972, OS#2971
Change-Id: Iebd2571726d1284a7431b3f9b23ad3185e832ed1
---
M src/common/rsl.c
1 file changed, 78 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/34/6634/1

diff --git a/src/common/rsl.c b/src/common/rsl.c
index 2eb0db1..877f5d8 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -1,7 +1,7 @@
 /* GSM TS 08.58 RSL, BTS Side */
 
 /* (C) 2011 by Andreas Eversberg 
- * (C) 2011-2014 by Harald Welte 
+ * (C) 2011-2017 by Harald Welte 
  *
  * All Rights Reserved
  *
@@ -135,18 +135,6 @@
  * support
  */
 
-/**
- * Handle GSM 08.58 7 Error Handling for the given input. This method will
- * send either a CHANNEL ACTIVATION NACK, MODE MODIFY NACK or ERROR REPORT
- * depending on the input of the method.
- *
- * TODO: actually make the decision
- */
-static int report_error(struct gsm_bts_trx *trx)
-{
-   return rsl_tx_error_report(trx, RSL_ERR_IE_CONTENT);
-}
-
 static struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
  const char *log_name)
 {
@@ -159,9 +147,11 @@
return NULL;
}
 
-   if (rc < 0)
+   if (rc < 0) {
LOGP(DRSL, LOGL_ERROR, "%s %smismatching chan_nr=0x%02x\n",
 gsm_ts_and_pchan_name(lchan->ts), log_name, chan_nr);
+   return NULL;
+   }
return lchan;
 }
 
@@ -643,14 +633,16 @@
 }
 
 /* 8.4.3 sending CHANnel ACTIVation Negative ACK */
-static int rsl_tx_chan_act_nack(struct gsm_lchan *lchan, uint8_t cause)
+static int _rsl_tx_chan_act_nack(struct gsm_bts_trx *trx, uint8_t chan_nr, 
uint8_t cause,
+struct gsm_lchan *lchan)
 {
struct msgb *msg;
-   uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
 
-   LOGP(DRSL, LOGL_NOTICE,
-   "%s Sending Channel Activated NACK: cause = 0x%02x\n",
-   gsm_lchan_name(lchan), cause);
+   if (lchan)
+   LOGP(DRSL, LOGL_NOTICE, "%s: ", gsm_lchan_name(lchan));
+   else
+   LOGP(DRSL, LOGL_NOTICE, "0x%02x: ", chan_nr);
+   LOGPC(DRSL, LOGL_NOTICE, "Sending Channel Activated NACK: cause = 
0x%02x\n", cause);
 
msg = rsl_msgb_alloc(sizeof(struct abis_rsl_dchan_hdr));
if (!msg)
@@ -659,9 +651,12 @@
/* 9.3.26 Cause */
msgb_tlv_put(msg, RSL_IE_CAUSE, 1, &cause);
rsl_dch_push_hdr(msg, RSL_MT_CHAN_ACTIV_NACK, chan_nr);
-   msg->trx = lchan->ts->trx;
+   msg->trx = trx;
 
return abis_bts_rsl_sendmsg(msg);
+}
+static int rsl_tx_chan_act_nack(struct gsm_lchan *lchan, uint8_t cause) {
+   return _rsl_tx_chan_act_nack(lchan->ts->trx, gsm_lchan2chan_nr(lchan), 
cause, lchan);
 }
 
 /* Send an RSL Channel Activation Ack if cause is zero, a Nack otherwise. */
@@ -1229,13 +1224,16 @@
 }
 
 /* 8.4.11 MODE MODIFY NEGATIVE ACKNOWLEDGE */
-static int rsl_tx_mode_modif_nack(struct gsm_lchan *lchan, uint8_t cause)
+static int _rsl_tx_mode_modif_nack(struct gsm_bts_trx *trx, uint8_t chan_nr, 
uint8_t cause,
+ struct gsm_lchan *lchan)
 {
struct msgb *msg;
-   uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
 
-   LOGP(DRSL, LOGL_NOTICE, "%s Tx MODE MODIFY NACK (cause = 0x%02x)\n",
-gsm_lchan_name(lchan), cause);
+   if (lchan)
+   LOGP(DRSL, LOGL_NOTICE, "%s: ", gsm_lchan_name(lchan));
+   else
+   LOGP(DRSL, LOGL_NOTICE, "0x%02x: ", chan_nr);
+   LOGPC(DRSL, LOGL_NOTICE, "Tx MODE MODIFY NACK (cause = 0x%02x)\n", 
cause);
 
msg = rsl_msgb_alloc(sizeof(struct abis_rsl_dchan_hdr));
if (!msg)
@@ -1247,11 +1245,15 @@
/* 9.3.26 Cause */
msgb_tlv_put(msg, RSL_IE_CAUSE, 1, &cause);
rsl_dch_push_hdr(msg, RSL_MT_MODE_MODIFY_NACK, chan_nr);
-   msg->lchan = lchan;
-   msg->trx = lchan->ts->trx;
+   msg->trx = trx;
 
return abis_bts_rsl_sendmsg(msg);
 }
+static int rsl_tx_mode_modif_nack(struct gsm_lchan *lchan, uint8_t cause)
+{
+   return _rsl_tx_mode_modif_nack(lchan->ts->trx, 
gsm_lchan2chan_nr(lchan), cause, lchan);
+}
+
 
 /* 8.4.10 MODE MODIFY ACK */
 static int rsl_tx_mode_modif_ack(struct gsm_lchan *lchan)
@@ -2190,6 +2192,52 @@
 pdch_act? "ACT" : "DEACT", rc);
 }
 
+/* handle a message with an RSL CHAN_NR that is incompatible/unknown */
+static int rsl_reject_unknown_lchan(struct msgb *msg)
+{
+   struct abis_rsl_common_hdr *rh = msgb_l2(msg);
+   struct abis_rsl_dchan_hdr *dch;
+   int rc;
+
+   /* Handle GSM 08.58 7 Error Handling for the given input

[PATCH] osmo-bts[master]: RSL: Ensure we don't accept DCHAN messages for CCHAN

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6635

RSL: Ensure we don't accept DCHAN messages for CCHAN

If the Channel Number IE points to a common channel, we cannot
accept such messages in code paths that only process dedicated
channels, such as RLL/DCHAN/IPA.

Related: OS#2972, OS#2971
Change-Id: I43a78bec63aeb36dd67043d237b27fe880209349
---
M src/common/rsl.c
1 file changed, 22 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/35/6635/1

diff --git a/src/common/rsl.c b/src/common/rsl.c
index 877f5d8..001d7e0 100644
--- a/src/common/rsl.c
+++ b/src/common/rsl.c
@@ -135,6 +135,16 @@
  * support
  */
 
+/* Is this channel number for a dedicated channel (true) or not (false) */
+static bool chan_nr_is_dchan(uint8_t chan_nr)
+{
+   /* See TS 48.058 9.3.1 */
+   if (chan_nr & 0x80)
+   return false;
+   else
+   return true;
+}
+
 static struct gsm_lchan *lchan_lookup(struct gsm_bts_trx *trx, uint8_t chan_nr,
  const char *log_name)
 {
@@ -2254,6 +2264,9 @@
}
msg->l3h = (unsigned char *)rh + sizeof(*rh);
 
+   if (!chan_nr_is_dchan(rh->chan_nr))
+   return rsl_reject_unknown_lchan(msg);
+
lchan = lchan_lookup(trx, rh->chan_nr, "RSL rx RLL: ");
if (!lchan) {
LOGP(DRLL, LOGL_NOTICE, "Rx RLL %s for unknown lchan\n",
@@ -2445,6 +2458,9 @@
}
msg->l3h = (unsigned char *)cch + sizeof(*cch);
 
+   if (chan_nr_is_dchan(cch->chan_nr))
+   return rsl_reject_unknown_lchan(msg);
+
msg->lchan = lchan_lookup(trx, cch->chan_nr, "RSL rx CCHAN: ");
if (!msg->lchan) {
LOGP(DRSL, LOGL_ERROR, "Rx RSL %s for unknown lchan\n",
@@ -2497,6 +2513,9 @@
return -EIO;
}
msg->l3h = (unsigned char *)dch + sizeof(*dch);
+
+   if (!chan_nr_is_dchan(dch->chan_nr))
+   return rsl_reject_unknown_lchan(msg);
 
msg->lchan = lchan_lookup(trx, dch->chan_nr, "RSL rx DCHAN: ");
if (!msg->lchan) {
@@ -2596,6 +2615,9 @@
}
msg->l3h = (unsigned char *)dch + sizeof(*dch);
 
+   if (!chan_nr_is_dchan(dch->chan_nr))
+   return rsl_reject_unknown_lchan(msg);
+
msg->lchan = lchan_lookup(trx, dch->chan_nr, "RSL rx IPACC: ");
if (!msg->lchan) {
LOGP(DRSL, LOGL_ERROR, "Rx RSL %s for unknow lchan\n",

-- 
To view, visit https://gerrit.osmocom.org/6635
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I43a78bec63aeb36dd67043d237b27fe880209349
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 


[PATCH] osmo-mgw[master]: mgcp_client: show failure by MGCP SDP section parsing test

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6638

mgcp_client: show failure by MGCP SDP section parsing test

To show how the current code fails, add test_sdp_section_start() to
mgcp_client_test.c, and temporarily accept failing output. This will be fixed
in change Ib0d5a9fc3020ff630eb3460209c1317f09254a92.

Change-Id: I5c6d3566b8f6dbf04c0cd8b127423f5295c19f8d
---
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
M tests/mgcp_client/mgcp_client_test.ok
3 files changed, 180 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/38/6638/1

diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index ef2fca8..588b313 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -271,6 +271,111 @@
fprintf(stderr, "%s() done\n", __func__);
 }
 
+struct sdp_section_start_test {
+   const char *body;
+   int expect_rc;
+   struct mgcp_response expect_params;
+};
+
+static struct sdp_section_start_test sdp_section_start_tests[] = {
+   {
+   .body = "",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "\n\n",
+   },
+   {
+   .body = "\r\n\r\n",
+   },
+   {
+   .body = "\n\r\n\r",
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n\r"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+};
+
+void test_sdp_section_start()
+{
+   int i;
+   int failures = 0;
+
+   for (i = 0; i < ARRAY_SIZE(sdp_section_start_tests); i++) {
+   int rc;
+   struct sdp_section_start_test *t = &sdp_section_start_tests[i];
+   struct mgcp_response *r = talloc_zero(ctx, struct 
mgcp_response);
+
+   r->body = talloc_strdup(r, t->body);
+
+   printf("\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "body: \"%s\"\n", osmo_escape_str(r->body, -1));
+
+   rc = mgcp_response_parse_params(r);
+
+   fprintf(stderr, "got rc=%d\n", rc);
+   if (rc != t->expect_rc) {
+   fprintf(stderr, "FAIL: Expected rc=%d\n", t->expect_rc);
+   failures++;
+   }
+   if (rc) {
+   talloc_free(r);
+   continue;
+   }
+
+   fprintf(stderr, "got audio_port=%u\n", 
t->expect_params.audio_port);
+   if (r->audio_port != t->expect_params.audio_port) {
+   fprintf(stderr, "FAIL: Expected audio_port=%u\n", 
t->expect_params.audio_port);
+   failures++;
+   }
+   talloc_free(r);
+   }
+
+   /* Expecting failures due to known bugs, will be resolved in a 
subsequent commit.
+   OSMO_ASSERT(!failures);
+   */
+}
+
 static const struct log_info_cat log_categories[] = {
 };
 
@@ -297,6 +402,7 @@
test_crcx();
test_mgcp_msg();
test_mgcp_client_cancel();
+   test_sdp_section_start();
 
printf("Done\n");
fprintf(stderr, "Done\n");
diff --git a/tests/mgcp_client/mgcp_client_test.err 
b/tests/mgcp_client/mgcp_client_test.err
index 8e9f648..9079c27 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -12,4 +12,58 @@
 - canceling again does nothing
 DLMGCP Cannot cancel, no such transaction: 1
 test_mgcp_client_cancel() done
+
+test_sdp_section_start() test [0]:
+body: ""
+got rc=0
+FAIL: Expected rc=-22
+got audio_port=0
+
+test_sdp_section_start() test [1]:
+body: "\n\n"

[PATCH] osmo-mgw[master]: mgcp_client: detect SDP section-start parsing errors

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6640

mgcp_client: detect SDP section-start parsing errors

After call to mgcp_find_section_end(), actually check the proper variable to
evaluate its return value.

Show in mgcp_client_test output that the parsing errors are fixed, and enable
the assertion that no tests should fail.

Change-Id: I62a2453cd9e2e7d5408423161fa65ec9c9989f98
---
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
3 files changed, 9 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/40/6640/1

diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index de940c0..e054593 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -262,7 +262,7 @@
 
/* Find beginning of the parameter (SDP) section */
data_ptr = mgcp_find_section_end(data);
-   if (!data) {
+   if (!data_ptr) {
LOGP(DLMGCP, LOGL_ERROR,
 "MGCP response: cannot find start of SDP parameters\n");
rc = -EINVAL;
diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index 588b313..50e21b5 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -371,9 +371,7 @@
talloc_free(r);
}
 
-   /* Expecting failures due to known bugs, will be resolved in a 
subsequent commit.
OSMO_ASSERT(!failures);
-   */
 }
 
 static const struct log_info_cat log_categories[] = {
diff --git a/tests/mgcp_client/mgcp_client_test.err 
b/tests/mgcp_client/mgcp_client_test.err
index 9079c27..7309242 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -15,9 +15,8 @@
 
 test_sdp_section_start() test [0]:
 body: ""
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 
 test_sdp_section_start() test [1]:
 body: "\n\n"
@@ -51,19 +50,16 @@
 
 test_sdp_section_start() test [7]:
 body: "some mgcp header data\r\nand header params\n\r\nm=audio 23\r\n"
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 
 test_sdp_section_start() test [8]:
 body: "some mgcp header data\r\nand header params\r\n\rm=audio 23\r\n"
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 
 test_sdp_section_start() test [9]:
 body: "some mgcp header data\r\nand header params\n\r\rm=audio 23\r\n"
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 Done

-- 
To view, visit https://gerrit.osmocom.org/6640
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I62a2453cd9e2e7d5408423161fa65ec9c9989f98
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] osmo-mgw[master]: mgcp_client: cosmetic: clean up SDP params parsing

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6639

mgcp_client: cosmetic: clean up SDP params parsing

The mgcp_response_parse_params() is in a jumble. Straighten out these cosmetic
issues:

- Move assertion of r->body close to its first use.
- Instead of a talloc_zero and osmo_strlcpy dance, simply use talloc_strdup().
- Drop the first unused invocation of mgcp_find_section_end().
- Drop unused assignment of data_ptr = data.
- In the log, mention "SDP" to clarify.
- Add a comment clarifying how we skip the section marker.

Change-Id: Icf1df761270777a142bc8ace75f2a10918314f73
---
M src/libosmo-mgcp-client/mgcp_client.c
1 file changed, 7 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/39/6639/1

diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index c340303..de940c0 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -251,26 +251,27 @@
 {
char *line;
int rc;
-   OSMO_ASSERT(r->body);
-   char *data = mgcp_find_section_end(r->body);
+   char *data;
char *data_ptr;
 
/* Since this functions performs a destructive parsing, we create a
 * local copy of the body data */
-   data = talloc_zero_size(r, strlen(r->body)+1);
+   OSMO_ASSERT(r->body);
+   data = talloc_strdup(r, r->body);
OSMO_ASSERT(data);
-   data_ptr = data;
-   osmo_strlcpy(data, r->body, strlen(r->body));
 
/* Find beginning of the parameter (SDP) section */
data_ptr = mgcp_find_section_end(data);
if (!data) {
LOGP(DLMGCP, LOGL_ERROR,
-"MGCP response: cannot find start of parameters\n");
+"MGCP response: cannot find start of SDP parameters\n");
rc = -EINVAL;
goto exit;
}
 
+   /* data_ptr now points to the beginning of the section-end-marker; 
for_each_non_empty_line()
+* skips any \r and \n characters for free, so we don't need to skip 
the marker. */
+
for_each_non_empty_line(line, data_ptr) {
if (!mgcp_line_is_valid(line))
return -EINVAL;

-- 
To view, visit https://gerrit.osmocom.org/6639
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf1df761270777a142bc8ace75f2a10918314f73
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] osmo-mgw[master]: mgcp_client: show failure by MGCP SDP section parsing test

2018-02-21 Thread Neels Hofmeyr

mgcp_client: show failure by MGCP SDP section parsing test

To show how the current code fails, add test_sdp_section_start() to
mgcp_client_test.c, and temporarily accept failing output. This will be fixed
in change I62a2453cd9e2e7d5408423161fa65ec9c9989f98.

Change-Id: I5c6d3566b8f6dbf04c0cd8b127423f5295c19f8d
---
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
M tests/mgcp_client/mgcp_client_test.ok
3 files changed, 180 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/38/6638/2

diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index ef2fca8..588b313 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -271,6 +271,111 @@
fprintf(stderr, "%s() done\n", __func__);
 }
 
+struct sdp_section_start_test {
+   const char *body;
+   int expect_rc;
+   struct mgcp_response expect_params;
+};
+
+static struct sdp_section_start_test sdp_section_start_tests[] = {
+   {
+   .body = "",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "\n\n",
+   },
+   {
+   .body = "\r\n\r\n",
+   },
+   {
+   .body = "\n\r\n\r",
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r\n"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n\r"
+   "m=audio 23\r\n",
+   .expect_params = {
+   .audio_port = 23,
+   },
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\n"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\r\n\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+   {
+   .body = "some mgcp header data\r\nand header params"
+   "\n\r\r"
+   "m=audio 23\r\n",
+   .expect_rc = -EINVAL,
+   },
+};
+
+void test_sdp_section_start()
+{
+   int i;
+   int failures = 0;
+
+   for (i = 0; i < ARRAY_SIZE(sdp_section_start_tests); i++) {
+   int rc;
+   struct sdp_section_start_test *t = &sdp_section_start_tests[i];
+   struct mgcp_response *r = talloc_zero(ctx, struct 
mgcp_response);
+
+   r->body = talloc_strdup(r, t->body);
+
+   printf("\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "\n%s() test [%d]:\n", __func__, i);
+   fprintf(stderr, "body: \"%s\"\n", osmo_escape_str(r->body, -1));
+
+   rc = mgcp_response_parse_params(r);
+
+   fprintf(stderr, "got rc=%d\n", rc);
+   if (rc != t->expect_rc) {
+   fprintf(stderr, "FAIL: Expected rc=%d\n", t->expect_rc);
+   failures++;
+   }
+   if (rc) {
+   talloc_free(r);
+   continue;
+   }
+
+   fprintf(stderr, "got audio_port=%u\n", 
t->expect_params.audio_port);
+   if (r->audio_port != t->expect_params.audio_port) {
+   fprintf(stderr, "FAIL: Expected audio_port=%u\n", 
t->expect_params.audio_port);
+   failures++;
+   }
+   talloc_free(r);
+   }
+
+   /* Expecting failures due to known bugs, will be resolved in a 
subsequent commit.
+   OSMO_ASSERT(!failures);
+   */
+}
+
 static const struct log_info_cat log_categories[] = {
 };
 
@@ -297,6 +402,7 @@
test_crcx();
test_mgcp_msg();
test_mgcp_client_cancel();
+   test_sdp_section_start();
 
printf("Done\n");
fprintf(stderr, "Done\n");
diff --git a/tests/mgcp_client/mgcp_client_test.err 
b/tests/mgcp_client/mgcp_client_test.err
index 8e9f648..9079c27 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -12,4 +12,58 @@
 - canceling again does nothing
 DLMGCP Cannot cancel, no such transaction: 1
 test_mgcp_client_cancel() done
+
+test_sdp_section_start() test [0]:
+body: ""
+got rc=0
+FAIL: Expected rc=-22
+got audio_port=0
+
+test_sdp_section_start() test [1]:
+body: "\n\n"
+got rc=0
+got audio_port=0
+
+test_sdp_sec

[PATCH] osmo-mgw[master]: mgcp_client: detect SDP section-start parsing errors

2018-02-21 Thread Neels Hofmeyr

mgcp_client: detect SDP section-start parsing errors

After call to mgcp_find_section_end(), actually check the proper variable to
evaluate its return value.

Show in mgcp_client_test output that the parsing errors are fixed, and enable
the assertion that no tests should fail.

Change-Id: I62a2453cd9e2e7d5408423161fa65ec9c9989f98
---
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
3 files changed, 9 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/40/6640/2

diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index de940c0..e054593 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -262,7 +262,7 @@
 
/* Find beginning of the parameter (SDP) section */
data_ptr = mgcp_find_section_end(data);
-   if (!data) {
+   if (!data_ptr) {
LOGP(DLMGCP, LOGL_ERROR,
 "MGCP response: cannot find start of SDP parameters\n");
rc = -EINVAL;
diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index 588b313..50e21b5 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -371,9 +371,7 @@
talloc_free(r);
}
 
-   /* Expecting failures due to known bugs, will be resolved in a 
subsequent commit.
OSMO_ASSERT(!failures);
-   */
 }
 
 static const struct log_info_cat log_categories[] = {
diff --git a/tests/mgcp_client/mgcp_client_test.err 
b/tests/mgcp_client/mgcp_client_test.err
index 9079c27..7309242 100644
--- a/tests/mgcp_client/mgcp_client_test.err
+++ b/tests/mgcp_client/mgcp_client_test.err
@@ -15,9 +15,8 @@
 
 test_sdp_section_start() test [0]:
 body: ""
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 
 test_sdp_section_start() test [1]:
 body: "\n\n"
@@ -51,19 +50,16 @@
 
 test_sdp_section_start() test [7]:
 body: "some mgcp header data\r\nand header params\n\r\nm=audio 23\r\n"
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 
 test_sdp_section_start() test [8]:
 body: "some mgcp header data\r\nand header params\r\n\rm=audio 23\r\n"
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 
 test_sdp_section_start() test [9]:
 body: "some mgcp header data\r\nand header params\n\r\rm=audio 23\r\n"
-got rc=0
-FAIL: Expected rc=-22
-got audio_port=0
+DLMGCP MGCP response: cannot find start of SDP parameters
+got rc=-22
 Done

-- 
To view, visit https://gerrit.osmocom.org/6640
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I62a2453cd9e2e7d5408423161fa65ec9c9989f98
Gerrit-PatchSet: 2
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Jenkins Builder


[PATCH] osmo-mgw[master]: mgcp_client: cosmetic: clean up SDP params parsing

2018-02-21 Thread Neels Hofmeyr

mgcp_client: cosmetic: clean up SDP params parsing

The mgcp_response_parse_params() is in a jumble. Straighten out these cosmetic
issues:

- Move assertion of r->body close to its first use.
- Instead of a talloc_zero and osmo_strlcpy dance, simply use talloc_strdup().
- Drop the first unused invocation of mgcp_find_section_end().
- Drop unused assignment of data_ptr = data.
- In the log, mention "SDP" to clarify.
- Add a comment clarifying how we skip the section marker.

Change-Id: Icf1df761270777a142bc8ace75f2a10918314f73
---
M src/libosmo-mgcp-client/mgcp_client.c
1 file changed, 7 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/39/6639/2

diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index c340303..de940c0 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -251,26 +251,27 @@
 {
char *line;
int rc;
-   OSMO_ASSERT(r->body);
-   char *data = mgcp_find_section_end(r->body);
+   char *data;
char *data_ptr;
 
/* Since this functions performs a destructive parsing, we create a
 * local copy of the body data */
-   data = talloc_zero_size(r, strlen(r->body)+1);
+   OSMO_ASSERT(r->body);
+   data = talloc_strdup(r, r->body);
OSMO_ASSERT(data);
-   data_ptr = data;
-   osmo_strlcpy(data, r->body, strlen(r->body));
 
/* Find beginning of the parameter (SDP) section */
data_ptr = mgcp_find_section_end(data);
if (!data) {
LOGP(DLMGCP, LOGL_ERROR,
-"MGCP response: cannot find start of parameters\n");
+"MGCP response: cannot find start of SDP parameters\n");
rc = -EINVAL;
goto exit;
}
 
+   /* data_ptr now points to the beginning of the section-end-marker; 
for_each_non_empty_line()
+* skips any \r and \n characters for free, so we don't need to skip 
the marker. */
+
for_each_non_empty_line(line, data_ptr) {
if (!mgcp_line_is_valid(line))
return -EINVAL;

-- 
To view, visit https://gerrit.osmocom.org/6639
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Icf1df761270777a142bc8ace75f2a10918314f73
Gerrit-PatchSet: 2
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Jenkins Builder


osmo-trx[master]: Add initial support for logging, vty, ctrl

2018-02-21 Thread Pau Espin Pedrol

Patch Set 4:

(2 comments)

https://gerrit.osmocom.org/#/c/6619/4/CommonLibs/debug.c
File CommonLibs/debug.c:

Line 9: .description = "Transciever",
> _ei_ not _ie_ because its receiver, not reciever and "Transceiver" is from 
Typo indeed :-)


https://gerrit.osmocom.org/#/c/6619/4/CommonLibs/debug.h
File CommonLibs/debug.h:

Line 7: DTRX,
> I'm honestly not sure if it makes sense to start a category with this name.
I don't want to add even more changes to a lot of lines now to set different 
categories for each log line, so I'll use DMAIN for now and future commits can 
work on this.


-- 
To view, visit https://gerrit.osmocom.org/6619
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-HasComments: Yes


[PATCH] osmo-bts[master]: gsm_data_shared: extend bts feature list with speech codecs

2018-02-21 Thread dexter

Review at  https://gerrit.osmocom.org/6641

gsm_data_shared: extend bts feature list with speech codecs

The feature list does not cover any speech codec related information.

- Add speech codec related items to feature list.

Change-Id: If6d50c6f4e2348b23f31c3415b0f5577a3f5be50
---
M include/osmo-bts/gsm_data_shared.h
M src/common/gsm_data_shared.c
2 files changed, 12 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/41/6641/1

diff --git a/include/osmo-bts/gsm_data_shared.h 
b/include/osmo-bts/gsm_data_shared.h
index 6c1383f..1571929 100644
--- a/include/osmo-bts/gsm_data_shared.h
+++ b/include/osmo-bts/gsm_data_shared.h
@@ -525,7 +525,8 @@
 };
 
 /* N. B: always add new features to the end of the list (right before 
_NUM_BTS_FEAT) to avoid breaking compatibility
-   with BTS compiled against earlier version of this header */
+   with BTS compiled against earlier version of this header. Also make sure 
that the description strings
+   gsm_bts_features_descs[] in gsm_data_shared.c are also updated accordingly! 
*/
 enum gsm_bts_features {
BTS_FEAT_HSCSD,
BTS_FEAT_GPRS,
@@ -536,6 +537,11 @@
BTS_FEAT_OML_ALERTS,
BTS_FEAT_AGCH_PCH_PROP,
BTS_FEAT_CBCH,
+   BTS_FEAT_SPEECH_F_V1,
+   BTS_FEAT_SPEECH_H_V1,
+   BTS_FEAT_SPEECH_F_EFR,
+   BTS_FEAT_SPEECH_F_AMR,
+   BTS_FEAT_SPEECH_H_AMR,
_NUM_BTS_FEAT
 };
 
diff --git a/src/common/gsm_data_shared.c b/src/common/gsm_data_shared.c
index 1ef223c..e5a5ee6 100644
--- a/src/common/gsm_data_shared.c
+++ b/src/common/gsm_data_shared.c
@@ -117,6 +117,11 @@
{ BTS_FEAT_OML_ALERTS,  "OML Alerts" },
{ BTS_FEAT_AGCH_PCH_PROP,   "AGCH/PCH proportional allocation" },
{ BTS_FEAT_CBCH,"CBCH" },
+   { BTS_FEAT_SPEECH_F_V1, "Fullrate speech V1" },
+   { BTS_FEAT_SPEECH_H_V1, "Halfrate speech V1" },
+   { BTS_FEAT_SPEECH_F_EFR,"Fullrate speech EFR" },
+   { BTS_FEAT_SPEECH_F_AMR,"Fullrate speech AMR" },
+   { BTS_FEAT_SPEECH_H_AMR,"Halfrate speech AMR" },
{ 0, NULL }
 };
 

-- 
To view, visit https://gerrit.osmocom.org/6641
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If6d50c6f4e2348b23f31c3415b0f5577a3f5be50
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: dexter 


[PATCH] osmo-bts[master]: octphy: ensure all BTS models set features

2018-02-21 Thread dexter

Review at  https://gerrit.osmocom.org/6642

octphy: ensure all BTS models set features

Most of the BTS models do not or do register not all of thier
features to the the feature list.

- Update/extend the feature lists for all BTS-Models

Change-Id: I26765a64153368016921c2ac115b1c4aec9bc5e4
---
M src/osmo-bts-litecell15/main.c
M src/osmo-bts-octphy/l1_if.c
M src/osmo-bts-sysmo/main.c
M src/osmo-bts-trx/main.c
M src/osmo-bts-virtual/main.c
5 files changed, 28 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/42/6642/1

diff --git a/src/osmo-bts-litecell15/main.c b/src/osmo-bts-litecell15/main.c
index 97b5359..dcbd9f5 100644
--- a/src/osmo-bts-litecell15/main.c
+++ b/src/osmo-bts-litecell15/main.c
@@ -92,8 +92,14 @@
}
 
gsm_bts_set_feature(bts, BTS_FEAT_GPRS);
+   gsm_bts_set_feature(bts, BTS_FEAT_EGPRS);
gsm_bts_set_feature(bts, BTS_FEAT_OML_ALERTS);
gsm_bts_set_feature(bts, BTS_FEAT_AGCH_PCH_PROP);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_EFR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_AMR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_AMR);
 
bts_model_vty_init(bts);
 
diff --git a/src/osmo-bts-octphy/l1_if.c b/src/osmo-bts-octphy/l1_if.c
index dde993d..e5fcd98 100644
--- a/src/osmo-bts-octphy/l1_if.c
+++ b/src/osmo-bts-octphy/l1_if.c
@@ -791,6 +791,11 @@
 
gsm_bts_set_feature(bts, BTS_FEAT_GPRS);
gsm_bts_set_feature(bts, BTS_FEAT_OML_ALERTS);
+#if 
defined(cOCTVC1_GSM_LOGICAL_CHANNEL_COMBINATION_ENUM_FCCH_SCH_BCCH_CCCH_SDCCH4_CBCH_SACCHC4)
 && defined(cOCTVC1_GSM_LOGICAL_CHANNEL_COMBINATION_ENUM_SDCCH8_CBCH_SACCHC8)
+   gsm_bts_set_feature(bts, BTS_FEAT_CBCH);
+#endif
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_V1);
 
bts_model_vty_init(bts);
 
diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c
index f52ecdd..6118b60 100644
--- a/src/osmo-bts-sysmo/main.c
+++ b/src/osmo-bts-sysmo/main.c
@@ -94,6 +94,11 @@
gsm_bts_set_feature(bts, BTS_FEAT_EGPRS);
gsm_bts_set_feature(bts, BTS_FEAT_OML_ALERTS);
gsm_bts_set_feature(bts, BTS_FEAT_AGCH_PCH_PROP);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_EFR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_AMR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_AMR);
 
bts_model_vty_init(bts);
 
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index 973a611..38bb881 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -120,6 +120,11 @@
 
gsm_bts_set_feature(bts, BTS_FEAT_GPRS);
gsm_bts_set_feature(bts, BTS_FEAT_OML_ALERTS);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_EFR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_AMR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_AMR);
 
bts_model_vty_init(bts);
 
diff --git a/src/osmo-bts-virtual/main.c b/src/osmo-bts-virtual/main.c
index 8459107..7815a34 100644
--- a/src/osmo-bts-virtual/main.c
+++ b/src/osmo-bts-virtual/main.c
@@ -61,6 +61,13 @@
btsb = bts_role_bts(bts);
btsb->support.ciphers = CIPHER_A5(1) | CIPHER_A5(2) | CIPHER_A5(3);
 
+   gsm_bts_set_feature(bts, BTS_FEAT_OML_ALERTS);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_V1);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_EFR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_F_AMR);
+   gsm_bts_set_feature(bts, BTS_FEAT_SPEECH_H_AMR);
+
bts_model_vty_init(bts);
 
return 0;

-- 
To view, visit https://gerrit.osmocom.org/6642
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I26765a64153368016921c2ac115b1c4aec9bc5e4
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: dexter 


[PATCH] osmo-bts[master]: vty: display bts features in vty command show bts

2018-02-21 Thread dexter

Review at  https://gerrit.osmocom.org/6643

vty: display bts features in vty command show bts

The VTY command show bts does not display the bts specific
features yet.

- Also display the feature list in snow-bts

Change-Id: I509f2a7bbfa96c70bdfea4ff2488ee371e914620
---
M src/common/vty.c
1 file changed, 20 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/43/6643/1

diff --git a/src/common/vty.c b/src/common/vty.c
index 5abc90e..55c1e0f 100644
--- a/src/common/vty.c
+++ b/src/common/vty.c
@@ -736,6 +736,24 @@
return len;
 }
 
+static void bts_dump_vty_features(struct vty *vty, struct gsm_bts *bts)
+{
+   unsigned int i;
+   bool no_features = true;
+   vty_out(vty, "  Features:%s", VTY_NEWLINE);
+
+   for (i = 0; i < _NUM_BTS_FEAT; i++) {
+   if (gsm_bts_has_feature(bts, i)) {
+   vty_out(vty, "%03u ", i);
+   vty_out(vty, "%-40s%s", 
get_value_string(gsm_bts_features_descs, i), VTY_NEWLINE);
+   no_features = false;
+   }
+   }
+
+   if (no_features)
+   vty_out(vty, "(not available)%s", VTY_NEWLINE);
+}
+
 static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts)
 {
struct gsm_bts_role_bts *btsb = bts->role;
@@ -788,6 +806,8 @@
vty_out(vty, "%s", VTY_NEWLINE);
}
}
+
+   bts_dump_vty_features(vty, bts);
 }
 
 

-- 
To view, visit https://gerrit.osmocom.org/6643
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I509f2a7bbfa96c70bdfea4ff2488ee371e914620
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: dexter 


[PATCH] osmo-bts[master]: bts: use feature list instead of speech codec table

2018-02-21 Thread dexter

Review at  https://gerrit.osmocom.org/6644

bts: use feature list instead of speech codec table

osmo-bts has a table of pchan/channel mode combinations for every
bts. This table models the codec capabilitys of the BTS hardware.
However, having the speech codec apabilities modeled inside the
BTS feature list would be much more comfortable and since the
feature list is communicated back to the BSC we would get the
codec capabilities inside the BSC domain as well.

- remove the pchan/channel mode tables
- set speech codec variants for each BTS type
- fix bts_supports_cm so that it queries the feature list

Change-Id: I977dc729ba856631245aedf76afd48eac92166f7
---
M include/osmo-bts/bts.h
M include/osmo-bts/gsm_data.h
M src/common/bts.c
M src/common/rsl.c
M src/osmo-bts-octphy/l1_if.c
M src/osmo-bts-sysmo/main.c
M src/osmo-bts-trx/main.c
M tests/misc/misc_test.c
8 files changed, 53 insertions(+), 79 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/44/6644/1

diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index 2f63e37..4d6e347 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -45,8 +45,8 @@
 
 int bts_main(int argc, char **argv);
 
-int bts_supports_cm(struct gsm_bts_role_bts *bts,
-   enum gsm_phys_chan_config pchan, enum gsm48_chan_mode cm);
+int bts_supports_cm(struct gsm_bts *bts, enum gsm_phys_chan_config pchan,
+   enum gsm48_chan_mode cm);
 
 #endif /* _BTS_H */
 
diff --git a/include/osmo-bts/gsm_data.h b/include/osmo-bts/gsm_data.h
index 853b445..4b834b5 100644
--- a/include/osmo-bts/gsm_data.h
+++ b/include/osmo-bts/gsm_data.h
@@ -33,11 +33,6 @@
struct pcu_sock_state *pcu_state;
 };
 
-struct bts_cm {
-   enum gsm_phys_chan_config pchan;
-   enum gsm48_chan_mode cm;
-};
-
 /* data structure for BTS related data specific to the BTS role */
 struct gsm_bts_role_bts {
struct {
@@ -94,7 +89,6 @@
bool rtp_jitter_adaptive;
struct {
uint8_t ciphers;/* flags A5/1==0x1, A5/2==0x2, 
A5/3==0x4 */
-   const struct bts_cm *cm; /* Table with supp. ch rate/mode 
combinations */
} support;
struct {
uint8_t tc4_ctr;
diff --git a/src/common/bts.c b/src/common/bts.c
index 31afba4..7849d61 100644
--- a/src/common/bts.c
+++ b/src/common/bts.c
@@ -676,32 +676,45 @@
return &btsb->gsm_time;
 }
 
-int bts_supports_cm(struct gsm_bts_role_bts *bts,
-   enum gsm_phys_chan_config pchan, enum gsm48_chan_mode cm)
+int bts_supports_cm(struct gsm_bts *bts, enum gsm_phys_chan_config pchan,
+   enum gsm48_chan_mode cm)
 {
-   const struct bts_cm *supported;
-   int i;
+   enum gsm_bts_features feature = _NUM_BTS_FEAT;
 
-   supported = bts->support.cm;
-
-   /* Check if we got a list with supported codec, if not, no list has
-* been configured yet for that BTS. In that case we will just skip
-* and accept any combination */
-   if (supported == NULL)
-   return 1;
-
-   for (i = 0;; i++) {
-   /* If we manage to find the given combination in the list,
-* we know that the pchan/cm combination is supported */
-   if (supported[i].pchan == pchan && supported[i].cm == cm)
-   return 1;
-
-   /* When we hit the terminator, we know that the given
-* pchan/cm combination is not supported because it
-* is not in the list. */
-   if (supported[i].pchan == _GSM_PCHAN_MAX)
+   /* Before the requested pchan/cm combination can be checked, we need to
+* convert it to a feature identifier we can check */
+   if (pchan == GSM_PCHAN_TCH_F) {
+   switch(cm) {
+   case GSM48_CMODE_SPEECH_V1:
+   feature = BTS_FEAT_SPEECH_F_V1;
+   break;
+   case GSM48_CMODE_SPEECH_EFR:
+   feature = BTS_FEAT_SPEECH_F_EFR;
+   break;
+   case GSM48_CMODE_SPEECH_AMR:
+   feature = BTS_FEAT_SPEECH_F_AMR;
+   break;
+   default:
+   /* Invalid speech codec type => Not supported! */
return 0;
+   }
+   } else if (pchan == GSM_PCHAN_TCH_H) {
+   switch(cm) {
+   case GSM48_CMODE_SPEECH_V1:
+   feature = BTS_FEAT_SPEECH_H_V1;
+   break;
+   case GSM48_CMODE_SPEECH_AMR:
+   feature = BTS_FEAT_SPEECH_H_AMR;
+   break;
+   default:
+   /* Invalid speech codec type => Not supported! */
+   return 0;
+   }
}
 
+   /* Check if the feature is supported by this BTS */
+   if (gsm_bts_has_feature(bts, feature))
+   return 

[PATCH] osmo-sgsn[master]: sgsn_test: guard against struct gprs_ra_id changing

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6645

sgsn_test: guard against struct gprs_ra_id changing

sgsn_test initializes various struct gprs_ra_id without naming the actual
members, which is vulnerable to struct member re-ordering. Name the members
explicitly.

An upcoming ABI change in libosmocore would cause test failures here without
this patch.

Change-Id: I517ed9edf77fac37d9de7a39df24c419a8a65d96
---
M tests/sgsn/sgsn_test.c
1 file changed, 3 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/45/6645/1

diff --git a/tests/sgsn/sgsn_test.c b/tests/sgsn/sgsn_test.c
index 4237349..2fbd6e4 100644
--- a/tests/sgsn/sgsn_test.c
+++ b/tests/sgsn/sgsn_test.c
@@ -1644,7 +1644,7 @@
  */
 static void test_gmm_ptmsi_allocation(void)
 {
-   struct gprs_ra_id raid = {332, 112, 16464, 96};
+   struct gprs_ra_id raid = { .mnc=332, .mcc=112, .lac=16464, .rac=96};
struct sgsn_mm_ctx *ctx = NULL;
struct sgsn_mm_ctx *ictx;
uint32_t foreign_tlli;
@@ -1847,8 +1847,8 @@
  */
 static void test_gmm_routing_areas(void)
 {
-   struct gprs_ra_id raid1 = {332, 112, 16464, 96};
-   struct gprs_ra_id raid2 = {332, 112, 16464, 97};
+   struct gprs_ra_id raid1 = { .mnc=332, .mcc=112, .lac=16464, .rac=96};
+   struct gprs_ra_id raid2 = { .mnc=332, .mcc=112, .lac=16464, .rac=97};
struct sgsn_mm_ctx *ctx = NULL;
struct sgsn_mm_ctx *ictx;
uint32_t ptmsi1;

-- 
To view, visit https://gerrit.osmocom.org/6645
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I517ed9edf77fac37d9de7a39df24c419a8a65d96
Gerrit-PatchSet: 1
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


osmo-bts[master]: octphy: ensure all BTS models set features

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/6642
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I26765a64153368016921c2ac115b1c4aec9bc5e4
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


osmo-bts[master]: gsm_data_shared: extend bts feature list with speech codecs

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/6641
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: If6d50c6f4e2348b23f31c3415b0f5577a3f5be50
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


osmo-bts[master]: vty: display bts features in vty command show bts

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/6643
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I509f2a7bbfa96c70bdfea4ff2488ee371e914620
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


osmo-trx[master]: Depend on libosmocore and enable talloc reports

2018-02-21 Thread Vadim Yanitskiy

Patch Set 4:

I would prefer to integrate both talloc and signal handlers separately...

-- 
To view, visit https://gerrit.osmocom.org/6618
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: If345c89293fcd7d1ad4f17214eea339951f25a5d
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


[PATCH] osmo-trx[master]: osmo-trx.cpp: Move trx start and stop to helper functions

2018-02-21 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/6648

osmo-trx.cpp: Move trx start and stop to helper functions

Make main() smaller, and make it easier to replace cmdline parameters in
following commits.

Change-Id: I10eaaafe38ace2b7bb095a0ad1db70d6c06ee03b
---
M Transceiver52M/osmo-trx.cpp
1 file changed, 66 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/48/6648/1

diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 0326d0b..e8bd81a 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -108,6 +108,10 @@
 static struct trx_ctx *g_trx_ctx;
 static struct ctrl_handle *g_ctrlh;
 
+RadioDevice *usrp;
+RadioInterface *radio;
+Transceiver *transceiver;
+
 /* Setup configuration values
  * Don't query the existence of the Log.Level because it's a
  * mandatory value. That is, if it doesn't exist, the configuration
@@ -227,33 +231,30 @@
  * and decoding schemes. Also included are the socket interfaces for
  * connecting to the upper layer stack.
  */
-Transceiver *makeTransceiver(struct trx_config *config, RadioInterface *radio)
+int makeTransceiver(struct trx_config *config, RadioInterface *radio)
 {
-   Transceiver *trx;
VectorFIFO *fifo;
 
-   trx = new Transceiver(config->port, config->local_addr.c_str(),
+   transceiver = new Transceiver(config->port, config->local_addr.c_str(),
  config->remote_addr.c_str(), config->tx_sps,
  config->rx_sps, config->chans, GSM::Time(3,0),
  radio, config->rssi_offset);
-   if (!trx->init(config->filler, config->rtsc,
+   if (!transceiver->init(config->filler, config->rtsc,
   config->rach_delay, config->edge)) {
LOG(ALERT) << "Failed to initialize transceiver";
-   delete trx;
-   return NULL;
+   return -1;
}
 
for (size_t i = 0; i < config->chans; i++) {
fifo = radio->receiveFIFO(i);
-   if (fifo && trx->receiveFIFO(fifo, i))
+   if (fifo && transceiver->receiveFIFO(fifo, i))
continue;
 
LOG(ALERT) << "Could not attach FIFO to channel " << i;
-   delete trx;
-   return NULL;
+   return -1;
}
 
-   return trx;
+   return 0;
 }
 
 static void sig_handler(int signo)
@@ -501,13 +502,61 @@
return 0;
 }
 
-int main(int argc, char *argv[])
+static void trx_stop()
+{
+   std::cout << "Shutting down transceiver..." << std::endl;
+
+   delete transceiver;
+   delete radio;
+   delete usrp;
+}
+
+static int trx_start(struct trx_config *config)
 {
int type, chans, ref;
-   RadioDevice *usrp;
-   RadioInterface *radio = NULL;
-   Transceiver *trx = NULL;
RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
+
+   /* Create the low level device object */
+   if (config->mcbts)
+   iface = RadioDevice::MULTI_ARFCN;
+
+   if (config->extref)
+   ref = RadioDevice::REF_EXTERNAL;
+   else if (config->gpsref)
+   ref = RadioDevice::REF_GPS;
+   else
+   ref = RadioDevice::REF_INTERNAL;
+
+   usrp = RadioDevice::make(config->tx_sps, config->rx_sps, iface,
+config->chans, config->offset, 
config->tx_paths, config->rx_paths);
+   type = usrp->open(config->dev_args, ref, config->swap_channels);
+   if (type < 0) {
+   LOG(ALERT) << "Failed to create radio device" << std::endl;
+   goto shutdown;
+   }
+
+   /* Setup the appropriate device interface */
+   radio = makeRadioInterface(config, usrp, type);
+   if (!radio)
+   goto shutdown;
+
+   /* Create the transceiver core */
+   if(makeTransceiver(config, radio) < 0)
+   goto shutdown;
+
+   chans = transceiver->numChans();
+   std::cout << "-- Transceiver active with "
+ << chans << " channel(s)" << std::endl;
+
+   return 0;
+
+shutdown:
+   trx_stop();
+   return -1;
+}
+
+int main(int argc, char *argv[])
+{
struct trx_config config;
int rc;
 
@@ -589,48 +638,13 @@
 
srandom(time(NULL));
 
-   /* Create the low level device object */
-   if (config.mcbts)
-   iface = RadioDevice::MULTI_ARFCN;
-
-   if (config.extref)
-   ref = RadioDevice::REF_EXTERNAL;
-   else if (config.gpsref)
-   ref = RadioDevice::REF_GPS;
-   else
-   ref = RadioDevice::REF_INTERNAL;
-
-   usrp = RadioDevice::make(config.tx_sps, config.rx_sps, iface,
-config.chans, config.offset, config.tx_paths, 
config.rx_paths);
-   type = usrp->open(config.dev_args, ref, config.swap_channels);
-   if (type < 0) {
-   LOG(ALERT) << "Fail

[PATCH] osmo-trx[master]: Logger: Use libosmocore logging system

2018-02-21 Thread Pau Espin Pedrol
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6620

to look at the new patch set (#5).

Logger: Use libosmocore logging system

We still need an intermediate class Logger due to osmo-trx being
multi-threaded and requiring to have a lock to use libosmocore, which is
not thread safe.

Change-Id: I30baac89f53e927f8699d0586b43cccf88ecd493
---
M CommonLibs/Logger.cpp
M CommonLibs/Logger.h
M CommonLibs/Makefile.am
M Transceiver52M/osmo-trx.cpp
M tests/CommonLibs/LogTest.cpp
M tests/CommonLibs/LogTest.err
M tests/CommonLibs/LogTest.ok
M tests/CommonLibs/Makefile.am
8 files changed, 65 insertions(+), 190 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/20/6620/5

diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp
index 4c2a2d3..ac3de42 100644
--- a/CommonLibs/Logger.cpp
+++ b/CommonLibs/Logger.cpp
@@ -1,7 +1,5 @@
 /*
-* Copyright 2009, 2010 Free Software Foundation, Inc.
-* Copyright 2010 Kestrel Signal Processing, Inc.
-* Copyright 2011, 2012 Range Networks, Inc.
+* Copyright (C) 2018 sysmocom - s.f.m.c. GmbH
 *
 *
 * This software is distributed under the terms of the GNU Affero Public 
License.
@@ -39,55 +37,6 @@
 
 Mutex gLogToLock;
 
-// Global log level threshold:
-int config_log_level;
-
-/** Names of the logging levels. */
-const char *levelNames[] = {
-   "EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG"
-};
-int numLevels = 8;
-
-
-int levelStringToInt(const string& name)
-{
-   // Reverse search, since the numerically larger levels are more common.
-   for (int i=numLevels-1; i>=0; i--) {
-   if (name == levelNames[i]) return i;
-   }
-
-   // Common substitutions.
-   if (name=="INFORMATION") return 6;
-   if (name=="WARN") return 4;
-   if (name=="ERROR") return 3;
-   if (name=="CRITICAL") return 2;
-   if (name=="EMERGENCY") return 0;
-
-   // Unknown level.
-   return -1;
-}
-
-static std::string format(const char *fmt, ...)
-{
-   va_list ap;
-   char buf[300];
-   va_start(ap,fmt);
-   int n = vsnprintf(buf,300,fmt,ap);
-   va_end(ap);
-   if (n >= (300-4)) { strcpy(&buf[(300-4)],"..."); }
-   return std::string(buf);
-}
-
-const std::string timestr()
-{
-   struct timeval tv;
-   struct tm tm;
-   gettimeofday(&tv,NULL);
-   localtime_r(&tv.tv_sec,&tm);
-   unsigned tenths = tv.tv_usec / 10;  // Rounding down is ok.
-   return format(" 
%02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths);
-}
-
 std::ostream& operator<<(std::ostream& os, std::ostringstream& ss)
 {
return os << ss.str();
@@ -95,34 +44,18 @@
 
 Log::~Log()
 {
-   // Anything at or above LOG_CRIT is an "alarm".
-   if (mPriority <= LOG_ERR) {
-   cerr << mStream.str() << endl;
-   }
-
int mlen = mStream.str().size();
int neednl = (mlen==0 || mStream.str()[mlen-1] != '\n');
+   const char *fmt = neednl ? "%s\n" : "%s";
ScopedLock lock(gLogToLock);
// The COUT() macro prevents messages from stomping each other but adds 
uninteresting thread numbers,
// so just use std::cout.
-   std::cout << mStream.str();
-   if (neednl) std::cout<<"\n";
+   LOGP(mCategory, mPriority, fmt, mStream.str().c_str());
 }
 
 ostringstream& Log::get()
 {
-   assert(mPriority
 #include 
 
-extern int config_log_level;
+extern "C" {
+#include 
+#include "debug.h"
+}
 
-#define LOG_EMERG   0   /* system is unusable */
-#define LOG_ALERT   1   /* action must be taken immediately */
-#define LOG_CRIT2   /* critical conditions */
-#define LOG_ERR 3   /* error conditions */
-#define LOG_WARNING 4   /* warning conditions */
-#define LOG_NOTICE  5   /* normal but significant condition */
-#define LOG_INFO6   /* informational */
-#define LOG_DEBUG   7   /* debug-level messages */
-
-#define _LOG(level) \
-   Log(LOG_##level).get() << pthread_self() \
-   << timestr() << " " __FILE__  ":"  << __LINE__ << ":" << __FUNCTION__ 
<< ": "
-
-#define IS_LOG_LEVEL(wLevel) (config_log_level>=LOG_##wLevel)
-
-#ifdef NDEBUG
-#define LOG(wLevel) \
-   if (LOG_##wLevel!=LOG_DEBUG && IS_LOG_LEVEL(wLevel)) _LOG(wLevel)
-#else
-#define LOG(wLevel) \
-   if (IS_LOG_LEVEL(wLevel)) _LOG(wLevel)
+/* Translation for old log statements */
+#ifndef LOGL_ALERT
+#define LOGL_ALERT LOGL_FATAL
 #endif
+#ifndef LOGL_ERR
+#define LOGL_ERR LOGL_ERROR
+#endif
+#ifndef LOGL_WARNING
+#define LOGL_WARNING LOGL_NOTICE
+#endif
+
+#define LOG(level) \
+   Log(DMAIN, LOGL_##level).get() <<  "[tid=" << pthread_self() << "] "
+
+#define LOGC(category, level) \
+   Log(category, LOGL_##level).get() <<  "[tid=" << pthread_self() << "] "
 
 /**
A C++ stream-based thread-safe logger.
@@ -73,13 +64,14 @@
 
protected:
 
-   std::ostringstream mStream; ///< 

[PATCH] osmo-trx[master]: osmo-trx: Drop cmd lines and use VTY cfg

2018-02-21 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/6651

osmo-trx: Drop cmd lines and use VTY cfg

Change-Id: Ib8de1a5da4b3c0b6a49e00033f616e1d66656adf
---
M Transceiver52M/osmo-trx.cpp
1 file changed, 99 insertions(+), 319 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/51/6651/1

diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index b6daf08..82492fb 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -55,51 +55,12 @@
 #include "debug.h"
 }
 
-/* Samples-per-symbol for downlink path
- * 4 - Uses precision modulator (more computation, less distortion)
- * 1 - Uses minimized modulator (less computation, more distortion)
- *
- * Other values are invalid. Receive path (uplink) is always
- * downsampled to 1 sps. Default to 4 sps for all cases.
- */
-#define DEFAULT_TX_SPS 4
-
-/*
- * Samples-per-symbol for uplink (receiver) path
- * Do not modify this value. EDGE configures 4 sps automatically on
- * B200/B210 devices only. Use of 4 sps on the receive path for other
- * configurations is not supported.
- */
-#define DEFAULT_RX_SPS 1
-
-/* Default configuration parameters */
-#define DEFAULT_TRX_PORT   5700
-#define DEFAULT_TRX_IP "127.0.0.1"
-#define DEFAULT_CHANS  1
 #define DEFAULT_CONFIG_FILE"osmo-trx.cfg"
 
+#define charp2str(a) ((a) ? std::string(a) : std::string(""))
+
 struct trx_config {
-   std::string local_addr;
-   std::string remote_addr;
-   std::string dev_args;
char* config_file;
-   unsigned port;
-   unsigned tx_sps;
-   unsigned rx_sps;
-   unsigned chans;
-   unsigned rtsc;
-   unsigned rach_delay;
-   bool extref;
-   bool gpsref;
-   FillerType filler;
-   bool mcbts;
-   double offset;
-   double rssi_offset;
-   bool swap_channels;
-   bool edge;
-   int sched_rr;
-   std::vector rx_paths;
-   std::vector tx_paths;
 };
 
 volatile bool gshutdown = false;
@@ -112,80 +73,6 @@
 RadioInterface *radio;
 Transceiver *transceiver;
 
-/* Setup configuration values
- * Don't query the existence of the Log.Level because it's a
- * mandatory value. That is, if it doesn't exist, the configuration
- * table will crash or will have already crashed. Everything else we
- * can survive without and use default values if the database entries
- * are empty.
- */
-bool trx_setup_config(struct trx_config *config)
-{
-   std::string refstr, fillstr, divstr, mcstr, edgestr;
-   std::vector::const_iterator si;
-
-   if (config->mcbts && config->chans > 5) {
-   std::cout << "Unsupported number of channels" << std::endl;
-   return false;
-   }
-
-   edgestr = config->edge ? "Enabled" : "Disabled";
-   mcstr = config->mcbts ? "Enabled" : "Disabled";
-
-   if (config->extref)
-   refstr = "External";
-   else if (config->gpsref)
-   refstr = "GPS";
-   else
-   refstr = "Internal";
-
-   switch (config->filler) {
-   case FILLER_DUMMY:
-   fillstr = "Dummy bursts";
-   break;
-   case FILLER_ZERO:
-   fillstr = "Disabled";
-   break;
-   case FILLER_NORM_RAND:
-   fillstr = "Normal busrts with random payload";
-   break;
-   case FILLER_EDGE_RAND:
-   fillstr = "EDGE busrts with random payload";
-   break;
-   case FILLER_ACCESS_RAND:
-   fillstr = "Access busrts with random payload";
-   break;
-   }
-
-   std::ostringstream ost("");
-   ost << "Config Settings" << std::endl;
-   ost << "   Device args. " << config->dev_args << std::endl;
-   ost << "   TRX Base Port... " << config->port << std::endl;
-   ost << "   TRX Address. " << config->local_addr << 
std::endl;
-   ost << "   GSM Core Address." << config->remote_addr << 
std::endl;
-   ost << "   Channels " << config->chans << std::endl;
-   ost << "   Tx Samples-per-Symbol... " << config->tx_sps << std::endl;
-   ost << "   Rx Samples-per-Symbol... " << config->rx_sps << std::endl;
-   ost << "   EDGE support " << edgestr << std::endl;
-   ost << "   Reference... " << refstr << std::endl;
-   ost << "   C0 Filler Table. " << fillstr << std::endl;
-   ost << "   Multi-Carrier... " << mcstr << std::endl;
-   ost << "   Tuning offset... " << config->offset << std::endl;
-   ost << "   RSSI to dBm offset.. " << config->rssi_offset << 
std::endl;
-   ost << "   Swap channels... " << config->swap_channels << 
std::endl;
-   ost << "   Tx Antennas.";
-   for (si = config->tx_paths.begin(); si != 
config->tx_paths.end(); ++si)
-   ost << " '" << ((*si != "") ?

[PATCH] osmo-trx[master]: vty: Implement VTY cfg parsing for current parameters

2018-02-21 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/6650

vty: Implement VTY cfg parsing for current parameters

At this stage, osmo-trx still uses the cmdline parameters top run the
device, but it is already able to parse all the same parameters from a
cfg file through the VTY and filling a trx_ctx structure which will be
later used to drive the device. Device config can be printed in the VTY
with "show trx".

Change-Id: Ie084c1b30b63f91c6e7640832ec1797d9e813832
---
M CommonLibs/trx_vty.c
M CommonLibs/trx_vty.h
M Transceiver52M/osmo-trx.cpp
A doc/examples/osmo-trx-limesdr.cfg
4 files changed, 488 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/50/6650/1

diff --git a/CommonLibs/trx_vty.c b/CommonLibs/trx_vty.c
index b16cd24..73603b3 100644
--- a/CommonLibs/trx_vty.c
+++ b/CommonLibs/trx_vty.c
@@ -36,6 +36,22 @@
 
 static struct trx_ctx* g_trx_ctx;
 
+static const struct value_string clock_ref_names[] = {
+   { REF_INTERNAL, "internal" },
+   { REF_EXTERNAL, "external" },
+   { REF_GPS,  "gspdo" },
+   { 0,NULL }
+};
+
+static const struct value_string filler_names[] = {
+   { FILLER_DUMMY, "Dummy bursts" },
+   { FILLER_ZERO,  "Disabled" },
+   { FILLER_NORM_RAND, "Normal bursts with random payload" },
+   { FILLER_EDGE_RAND, "EDGE bursts with random payload" },
+   { FILLER_ACCESS_RAND,   "Access bursts with random payload" },
+   { 0,NULL }
+};
+
 struct trx_ctx *trx_from_vty(struct vty *v)
 {
 /* It can't hurt to force callers to continue to pass the vty instance
@@ -50,11 +66,18 @@
 
 enum trx_vty_node {
TRX_NODE = _LAST_OSMOVTY_NODE + 1,
+   CHAN_NODE,
 };
 
 static struct cmd_node trx_node = {
TRX_NODE,
"%s(config-trx)# ",
+   1,
+};
+
+static struct cmd_node chan_node = {
+   CHAN_NODE,
+   "%s(config-trx-chan)# ",
1,
 };
 
@@ -84,15 +107,363 @@
return CMD_SUCCESS;
 }
 
+DEFUN(cfg_remote_ip, cfg_remote_ip_cmd,
+   "remote-ip A.B.C.D",
+   "Set the IP address for the remote BTS\n"
+   "IPv4 Address\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   osmo_talloc_replace_string(trx, &trx->cfg.remote_addr, argv[0]);
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_base_port, cfg_base_port_cmd,
+   "base-port <0-65535>",
+   "Set the TRX Base Port\n"
+   "TRX Base Port\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   trx->cfg.base_port = atoi(argv[0]);
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_dev_args, cfg_dev_args_cmd,
+   "dev-args DESC",
+   "Set the device-specific arguments to pass to the device\n"
+   "Device-specific arguments\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   osmo_talloc_replace_string(trx, &trx->cfg.dev_args, argv[0]);
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_tx_sps, cfg_tx_sps_cmd,
+   "tx-sps (1|4)",
+   "Set the Tx Samples-per-Symbol\n"
+   "Tx Samples-per-Symbol\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   trx->cfg.tx_sps = atoi(argv[0]);
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_rx_sps, cfg_rx_sps_cmd,
+   "rx-sps (1|4)",
+   "Set the Rx Samples-per-Symbol\n"
+   "Rx Samples-per-Symbol\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   trx->cfg.rx_sps = atoi(argv[0]);
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_rtsc, cfg_rtsc_cmd,
+   "rtsc <0-7>",
+   "Set the Random Normal Burst test mode with TSC\n"
+   "TSC\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   if (trx->cfg.rach_delay_set) {
+   vty_out(vty, "rach-delay and rtsc options are 
mutual-exclusive%s",
+   VTY_NEWLINE);
+   return CMD_WARNING;
+   }
+
+   trx->cfg.rtsc_set = true;
+   trx->cfg.rtsc = atoi(argv[0]);
+   if (!trx->cfg.egprs) /* Don't override egprs which sets different 
filler */
+   trx->cfg.filler = FILLER_NORM_RAND;
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_rach_delay, cfg_rach_delay_cmd,
+   "rach-delay <0-68>",
+   "Set the Random Access Burst test mode with delay\n"
+   "RACH delay\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   if (trx->cfg.rtsc_set) {
+   vty_out(vty, "rach-delay and rtsc options are 
mutual-exclusive%s",
+   VTY_NEWLINE);
+   return CMD_WARNING;
+   }
+
+   if (trx->cfg.egprs) {
+   vty_out(vty, "rach-delay and egprs options are 
mutual-exclusive%s",
+   VTY_NEWLINE);
+   return CMD_WARNING;
+   }
+
+   trx->cfg.rach_delay_set = true;
+   trx->cfg.rach_delay = atoi(argv[0]);
+   trx->cfg.filler = FILLER_ACCESS_RAND;
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_clock_ref, cfg_clock_ref_cmd,
+   "clock-ref (internal|external|gpsdo)",
+   "Set the Reference Clock\n"
+   "Enab

osmo-trx[master]: Depend on libosmocore

2018-02-21 Thread Vadim Yanitskiy

Patch Set 5: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/6618
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: If345c89293fcd7d1ad4f17214eea339951f25a5d
Gerrit-PatchSet: 5
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


osmo-trx[master]: osmo-trx: set up signals using libosmocore helpers

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/6646/1/Transceiver52M/osmo-trx.cpp
File Transceiver52M/osmo-trx.cpp:

Line 248:   fprintf(stdout, "SIGINT received, shutting down\n");
We already printed, which signal was received.

Let's either drop the 'SIGINT received' part,
either drop the whole line?


-- 
To view, visit https://gerrit.osmocom.org/6646
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I86e78cd6054d0deff1b1aa061299d9f307e2a352
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


osmo-trx[master]: Move enums required by VTY to a separate header

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1: Code-Review-1

I support the idea of using a proper enum X instead of int.

But do we really have to move these enums away from classes?
I believe there should be a way to avoid this...

-- 
To view, visit https://gerrit.osmocom.org/6649
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I3d5b0576aa96869756f1629a40306c0043b6304b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


[PATCH] osmo-trx[master]: Add initial support for logging, vty, ctrl

2018-02-21 Thread Pau Espin Pedrol
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6619

to look at the new patch set (#5).

Add initial support for logging, vty, ctrl

Up to this point, the logging system, vty and ctrl are initialized and
can be used fine, though they don't have a lot of use yet.

Depends on libosmocore Change-Id Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9

Related: OS#2184

Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
---
M CommonLibs/Makefile.am
A CommonLibs/debug.c
A CommonLibs/debug.h
A CommonLibs/trx_vty.c
A CommonLibs/trx_vty.h
M Transceiver52M/Makefile.am
M Transceiver52M/osmo-trx.cpp
M configure.ac
8 files changed, 269 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/19/6619/5

diff --git a/CommonLibs/Makefile.am b/CommonLibs/Makefile.am
index fa0b285..843bc38 100644
--- a/CommonLibs/Makefile.am
+++ b/CommonLibs/Makefile.am
@@ -23,6 +23,7 @@
 
 AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES)
 AM_CXXFLAGS = -Wall -O3 -g -lpthread
+AM_CFLAGS = $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_CFLAGS)
 
 EXTRA_DIST = \
example.config \
@@ -36,7 +37,9 @@
Sockets.cpp \
Threads.cpp \
Timeval.cpp \
-   Logger.cpp
+   Logger.cpp \
+   trx_vty.c \
+   debug.c
 
 noinst_HEADERS = \
BitVector.h \
@@ -47,4 +50,6 @@
Threads.h \
Timeval.h \
Vector.h \
-   Logger.h
+   Logger.h \
+   trx_vty.h \
+   debug.h
diff --git a/CommonLibs/debug.c b/CommonLibs/debug.c
new file mode 100644
index 000..e4db2f3
--- /dev/null
+++ b/CommonLibs/debug.c
@@ -0,0 +1,18 @@
+#include 
+#include 
+#include "debug.h"
+
+/* default categories */
+static const struct log_info_cat default_categories[] = {
+   [DMAIN] = {
+   .name = "DMAIN",
+   .description = "Main generic category",
+   .color = NULL,
+   .enabled = 1, .loglevel = LOGL_NOTICE,
+   },
+};
+
+const struct log_info log_info = {
+   .cat = default_categories,
+   .num_cat = ARRAY_SIZE(default_categories),
+};
diff --git a/CommonLibs/debug.h b/CommonLibs/debug.h
new file mode 100644
index 000..7038f4c
--- /dev/null
+++ b/CommonLibs/debug.h
@@ -0,0 +1,8 @@
+#pragma once
+
+extern const struct log_info log_info;
+
+/* Debug Areas of the code */
+enum {
+   DMAIN,
+};
diff --git a/CommonLibs/trx_vty.c b/CommonLibs/trx_vty.c
new file mode 100644
index 000..b16cd24
--- /dev/null
+++ b/CommonLibs/trx_vty.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2012-2017 sysmocom - s.f.m.c. GmbH
+ * All Rights Reserved
+ *
+ * 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, see .
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include "trx_vty.h"
+#include "../config.h"
+
+static struct trx_ctx* g_trx_ctx;
+
+struct trx_ctx *trx_from_vty(struct vty *v)
+{
+/* It can't hurt to force callers to continue to pass the vty instance
+ * to this function, in case we'd like to retrieve the global
+ * trx instance from the vty at some point in the future. But
+ * until then, just return the global pointer, which should have been
+ * initialized by trx_vty_init().
+ */
+OSMO_ASSERT(g_trx_ctx);
+return g_trx_ctx;
+}
+
+enum trx_vty_node {
+   TRX_NODE = _LAST_OSMOVTY_NODE + 1,
+};
+
+static struct cmd_node trx_node = {
+   TRX_NODE,
+   "%s(config-trx)# ",
+   1,
+};
+
+DEFUN(cfg_trx, cfg_trx_cmd,
+   "trx",
+   "Configure the TRX\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   if (!trx)
+   return CMD_WARNING;
+
+   vty->node = TRX_NODE;
+
+   return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bind_ip, cfg_bind_ip_cmd,
+   "bind-ip A.B.C.D",
+   "Set the IP address for the local bind\n"
+   "IPv4 Address\n")
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   osmo_talloc_replace_string(trx, &trx->cfg.bind_addr, argv[0]);
+
+   return CMD_SUCCESS;
+}
+
+static int config_write_trx(struct vty *vty)
+{
+   struct trx_ctx *trx = trx_from_vty(vty);
+
+   vty_out(vty, "trx%s", VTY_NEWLINE);
+   if (trx->cfg.bind_addr)
+   vty_out(vty, " bind-ip %s%s", trx->cfg.bind_addr, VTY_NEWLINE);
+
+   return CMD_SUCCE

[PATCH] osmo-trx[master]: Depend on libosmocore

2018-02-21 Thread Pau Espin Pedrol
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6618

to look at the new patch set (#5).

Depend on libosmocore

Change-Id: If345c89293fcd7d1ad4f17214eea339951f25a5d
---
M Transceiver52M/Makefile.am
M configure.ac
M contrib/jenkins.sh
3 files changed, 27 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/18/6618/5

diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am
index f36f4d4..21104dc 100644
--- a/Transceiver52M/Makefile.am
+++ b/Transceiver52M/Makefile.am
@@ -22,7 +22,7 @@
 include $(top_srcdir)/Makefile.common
 
 AM_CPPFLAGS = -Wall $(STD_DEFINES_AND_INCLUDES) -I${srcdir}/common
-AM_CXXFLAGS = -lpthread
+AM_CXXFLAGS = -lpthread $(LIBOSMOCORE_CFLAGS)
 
 SUBDIRS = arm x86
 
@@ -92,7 +92,8 @@
$(ARCH_LA) \
$(GSM_LA) \
$(COMMON_LA) \
-   $(FFTWF_LIBS)
+   $(FFTWF_LIBS) \
+   $(LIBOSMOCORE_LIBS)
 
 if USRP1
 libtransceiver_la_SOURCES += USRPDevice.cpp
diff --git a/configure.ac b/configure.ac
index 5c034e5..cba4a0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,6 +73,8 @@
 AC_HEADER_TIME
 AC_C_BIGENDIAN
 
+PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.10.0)
+
 AC_ARG_WITH(usrp1, [
 AS_HELP_STRING([--with-usrp1],
 [enable USRP1 gnuradio based transceiver])
diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh
index 11def5c..5f1eed9 100755
--- a/contrib/jenkins.sh
+++ b/contrib/jenkins.sh
@@ -15,6 +15,11 @@
 mychroot_nocwd -w / "$@"
 }
 
+base="$PWD"
+deps="$base/deps"
+inst="$deps/install"
+export deps inst
+
 if [ -z "${INSIDE_CHROOT}" ]; then
 
 osmo-clean-workspace.sh
@@ -49,8 +54,24 @@
 fi
 fi
 
-### BUILD osmo-trx
+mkdir "$deps" || true
 
+osmo-build-dep.sh libosmocore "" --disable-doxygen
+
+verify_value_string_arrays_are_terminated.py $(find . -name "*.[hc]")
+
+export PKG_CONFIG_PATH="$inst/lib/pkgconfig:$PKG_CONFIG_PATH"
+export LD_LIBRARY_PATH="$inst/lib"
+
+set +x
+echo
+echo
+echo
+echo " === osmo-trx 
==="
+echo
+set -x
+
+cd "$base"
 autoreconf --install --force
 ./configure $INSTR
 $MAKE $PARALLEL_MAKE

-- 
To view, visit https://gerrit.osmocom.org/6618
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: If345c89293fcd7d1ad4f17214eea339951f25a5d
Gerrit-PatchSet: 5
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 


osmo-trx[master]: Move enums required by VTY to a separate header

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/6649/1//COMMIT_MSG
Commit Message:

Line 9: This patch is a preparation for next patches, which add full VTY cfg
Moreover, the commit message doesn't explain why
this is necessary :?


-- 
To view, visit https://gerrit.osmocom.org/6649
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I3d5b0576aa96869756f1629a40306c0043b6304b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


[PATCH] osmo-trx[master]: osmo-trx: Set up talloc ctx

2018-02-21 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/6647

osmo-trx: Set up talloc ctx

Change-Id: I67f1980fc615ab74371cbe1c4f83e987381299bc
---
M Transceiver52M/osmo-trx.cpp
1 file changed, 14 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/47/6647/1

diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 07fa5fe..40269e1 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -37,7 +37,9 @@
 #include 
 
 extern "C" {
+#include 
 #include 
+#include 
 #include "convolve.h"
 #include "convert.h"
 }
@@ -89,6 +91,8 @@
 };
 
 volatile bool gshutdown = false;
+
+static void *tall_trx_ctx;
 
 /* Setup configuration values
  * Don't query the existence of the Log.Level because it's a
@@ -247,6 +251,14 @@
case SIGTERM:
fprintf(stdout, "SIGINT received, shutting down\n");
gshutdown = true;
+   break;
+   case SIGABRT:
+   case SIGUSR1:
+   talloc_report(tall_trx_ctx, stderr);
+   talloc_report_full(tall_trx_ctx, stderr);
+   break;
+   case SIGUSR2:
+   talloc_report_full(tall_trx_ctx, stderr);
break;
default:
break;
@@ -486,6 +498,8 @@
RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
struct trx_config config;
 
+   tall_trx_ctx = talloc_named_const(NULL, 0, "OsmoTRX");
+   msgb_talloc_ctx_init(tall_trx_ctx, 0);
setup_signal_handlers();
 
 #ifdef HAVE_SSE3

-- 
To view, visit https://gerrit.osmocom.org/6647
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I67f1980fc615ab74371cbe1c4f83e987381299bc
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 


osmo-trx[master]: Add initial support for logging, vty, ctrl

2018-02-21 Thread Vadim Yanitskiy

Patch Set 4:

(2 comments)

https://gerrit.osmocom.org/#/c/6619/4/Transceiver52M/osmo-trx.cpp
File Transceiver52M/osmo-trx.cpp:

Line 79: #define DEFAULT_CONFIG_FILE"/etc/osmocom/osmo-trx.cfg"
I am not sure, is this common for Osmocom projects to
keep the configuration files in '/etc/osmocom/'?

For example, the way of OsmoBTS:

  static const char *config_file = "osmo-bts.cfg";

so, if a configuration file isn't specified by user,
the program will look for "osmo-bts.cfg" in
a current directory.


https://gerrit.osmocom.org/#/c/6619/4/doc/examples/osmo-trx-limesdr.cfg
File doc/examples/osmo-trx-limesdr.cfg:

Line 1: log stderr
This file is definitely unrelated to the change,
and could be a part of another one...


-- 
To view, visit https://gerrit.osmocom.org/6619
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


[PATCH] osmo-trx[master]: osmo-trx: set up signals using libosmocore helpers

2018-02-21 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/6646

osmo-trx: set up signals using libosmocore helpers

Change-Id: I86e78cd6054d0deff1b1aa061299d9f307e2a352
---
M Transceiver52M/osmo-trx.cpp
1 file changed, 20 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/46/6646/1

diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 16866f4..07fa5fe 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -37,6 +37,7 @@
 #include 
 
 extern "C" {
+#include 
 #include "convolve.h"
 #include "convert.h"
 }
@@ -240,20 +241,27 @@
 
 static void sig_handler(int signo)
 {
-   fprintf(stdout, "Received shutdown signal");
-   gshutdown = true;
+   fprintf(stdout, "signal %d received\n", signo);
+   switch (signo) {
+   case SIGINT:
+   case SIGTERM:
+   fprintf(stdout, "SIGINT received, shutting down\n");
+   gshutdown = true;
+   break;
+   default:
+   break;
+   }
 }
 
 static void setup_signal_handlers()
 {
-   if (signal(SIGINT, sig_handler) == SIG_ERR) {
-   fprintf(stderr, "Failed to install SIGINT signal handler\n");
-   exit(EXIT_FAILURE);
-   }
-   if (signal(SIGTERM, sig_handler) == SIG_ERR) {
-   fprintf(stderr, "Couldn't install SIGTERM signal handler\n");
-   exit( EXIT_FAILURE);
-   }
+   /* Handle keyboard interrupt SIGINT */
+   signal(SIGINT, &sig_handler);
+   signal(SIGTERM, &sig_handler);
+   signal(SIGABRT, &sig_handler);
+   signal(SIGUSR1, &sig_handler);
+   signal(SIGUSR2, &sig_handler);
+   osmo_init_ignore_signals();
 }
 
 
@@ -478,6 +486,8 @@
RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
struct trx_config config;
 
+   setup_signal_handlers();
+
 #ifdef HAVE_SSE3
printf("Info: SSE3 support compiled in");
 #ifdef HAVE___BUILTIN_CPU_SUPPORTS
@@ -511,8 +521,6 @@
if (set_sched_rr(config.sched_rr) < 0)
return EXIT_FAILURE;
}
-
-   setup_signal_handlers();
 
/* Check database sanity */
if (!trx_setup_config(&config)) {

-- 
To view, visit https://gerrit.osmocom.org/6646
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I86e78cd6054d0deff1b1aa061299d9f307e2a352
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 


osmo-trx[master]: Add initial support for logging, vty, ctrl

2018-02-21 Thread Vadim Yanitskiy

Patch Set 5:

(1 comment)

https://gerrit.osmocom.org/#/c/6619/5/CommonLibs/trx_vty.h
File CommonLibs/trx_vty.h:

Line 7: struct trx_ctx {
Please add a comment with brief description of this
structure and further plans, i.e. what is it going
to be used for?


-- 
To view, visit https://gerrit.osmocom.org/6619
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
Gerrit-PatchSet: 5
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


osmo-trx[master]: Logger: Use libosmocore logging system

2018-02-21 Thread Vadim Yanitskiy

Patch Set 4:

(2 comments)

And do we really need to test logging here?

It's already being tested in libosmocore,
so testing here for me seems useless...

https://gerrit.osmocom.org/#/c/6620/4/CommonLibs/Makefile.am
File CommonLibs/Makefile.am:

Line 26: AM_CFLAGS = $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) 
$(LIBOSMOVTY_CFLAGS)
We already have both VTY and CTRL cflags here,
so do we really need to duplicate?


https://gerrit.osmocom.org/#/c/6620/4/tests/CommonLibs/Makefile.am
File tests/CommonLibs/Makefile.am:

Line 4: AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOCTRL_LIBS) $(LIBOSMOVTY_LIBS)
The same question here...


-- 
To view, visit https://gerrit.osmocom.org/6620
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I30baac89f53e927f8699d0586b43cccf88ecd493
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


osmo-bts[master]: bts: use feature list instead of speech codec table

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/6644
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I977dc729ba856631245aedf76afd48eac92166f7
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


osmo-trx[master]: Add initial support for logging, vty, ctrl

2018-02-21 Thread Vadim Yanitskiy

Patch Set 5: Code-Review+1

(1 comment)

https://gerrit.osmocom.org/#/c/6619/5/Transceiver52M/osmo-trx.cpp
File Transceiver52M/osmo-trx.cpp:

Line 345:   config->config_file = (char *)DEFAULT_CONFIG_FILE;
Why do we need this cast?
It should already be (char *), am I wrong?


-- 
To view, visit https://gerrit.osmocom.org/6619
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
Gerrit-PatchSet: 5
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


osmo-bts[master]: RSL: Properly reject RSL CHAN_NR IE for incompatible PCHAN

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/6634
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Iebd2571726d1284a7431b3f9b23ad3185e832ed1
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


osmo-trx[master]: osmo-trx: Set up talloc ctx

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1: Code-Review+1

-- 
To view, visit https://gerrit.osmocom.org/6647
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I67f1980fc615ab74371cbe1c4f83e987381299bc
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: No


[PATCH] osmo-trx[master]: Move enums required by VTY to a separate header

2018-02-21 Thread Pau Espin Pedrol

Review at  https://gerrit.osmocom.org/6649

Move enums required by VTY to a separate header

This patch is a preparation for next patches, which add full VTY cfg
support.

Change-Id: I3d5b0576aa96869756f1629a40306c0043b6304b
---
M CommonLibs/Makefile.am
A CommonLibs/config_defs.h
M Transceiver52M/Transceiver.cpp
M Transceiver52M/Transceiver.h
M Transceiver52M/osmo-trx.cpp
M Transceiver52M/radioDevice.h
6 files changed, 56 insertions(+), 41 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/49/6649/1

diff --git a/CommonLibs/Makefile.am b/CommonLibs/Makefile.am
index 5d116f9..613af1e 100644
--- a/CommonLibs/Makefile.am
+++ b/CommonLibs/Makefile.am
@@ -52,4 +52,5 @@
Vector.h \
Logger.h \
trx_vty.h \
-   debug.h
+   debug.h \
+   config_defs.h
diff --git a/CommonLibs/config_defs.h b/CommonLibs/config_defs.h
new file mode 100644
index 000..8626166
--- /dev/null
+++ b/CommonLibs/config_defs.h
@@ -0,0 +1,20 @@
+#pragma once
+
+/*
+ * This file contains structures used by both VTY (C, dir CommonLibs) and
+ * osmo-trx (CXX, dir Transceiver52)
+ */
+
+enum FillerType {
+  FILLER_DUMMY,
+  FILLER_ZERO,
+  FILLER_NORM_RAND,
+  FILLER_EDGE_RAND,
+  FILLER_ACCESS_RAND,
+};
+
+enum ReferenceType {
+  REF_INTERNAL,
+  REF_EXTERNAL,
+  REF_GPS,
+};
diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index d9c231d..8ebd9ed 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -71,7 +71,7 @@
   }
 }
 
-bool TransceiverState::init(int filler, size_t sps, float scale, size_t rtsc, 
unsigned rach_delay)
+bool TransceiverState::init(FillerType filler, size_t sps, float scale, size_t 
rtsc, unsigned rach_delay)
 {
   signalVector *burst;
 
@@ -81,19 +81,19 @@
   for (size_t n = 0; n < 8; n++) {
 for (size_t i = 0; i < 102; i++) {
   switch (filler) {
-  case Transceiver::FILLER_DUMMY:
+  case FILLER_DUMMY:
 burst = generateDummyBurst(sps, n);
 break;
-  case Transceiver::FILLER_NORM_RAND:
+  case FILLER_NORM_RAND:
 burst = genRandNormalBurst(rtsc, sps, n);
 break;
-  case Transceiver::FILLER_EDGE_RAND:
+  case FILLER_EDGE_RAND:
 burst = generateEdgeBurst(rtsc);
 break;
-  case Transceiver::FILLER_ACCESS_RAND:
+  case FILLER_ACCESS_RAND:
 burst = genRandAccessBurst(rach_delay, sps, n);
 break;
-  case Transceiver::FILLER_ZERO:
+  case FILLER_ZERO:
   default:
 burst = generateEmptyBurst(sps, n);
   }
@@ -102,8 +102,8 @@
   fillerTable[i][n] = burst;
 }
 
-if ((filler == Transceiver::FILLER_NORM_RAND) ||
-(filler == Transceiver::FILLER_EDGE_RAND)) {
+if ((filler == FILLER_NORM_RAND) ||
+(filler == FILLER_EDGE_RAND)) {
 chanType[n] = TSC;
 }
   }
@@ -161,7 +161,7 @@
  * are still expected to report clock indications through control channel
  * activity.
  */
-bool Transceiver::init(int filler, size_t rtsc, unsigned rach_delay, bool edge)
+bool Transceiver::init(FillerType filler, size_t rtsc, unsigned rach_delay, 
bool edge)
 {
   int d_srcport, d_dstport, c_srcport, c_dstport;
 
diff --git a/Transceiver52M/Transceiver.h b/Transceiver52M/Transceiver.h
index ad7a469..f9b54f0 100644
--- a/Transceiver52M/Transceiver.h
+++ b/Transceiver52M/Transceiver.h
@@ -30,6 +30,10 @@
 #include 
 #include 
 
+extern "C" {
+#include "config_defs.h"
+}
+
 class Transceiver;
 
 /** Channel descriptor for transceiver object and channel number pair */
@@ -54,7 +58,7 @@
   ~TransceiverState();
 
   /* Initialize a multiframe slot in the filler table */
-  bool init(int filler, size_t sps, float scale, size_t rtsc, unsigned 
rach_delay);
+  bool init(FillerType filler, size_t sps, float scale, size_t rtsc, unsigned 
rach_delay);
 
   int chanType[8];
 
@@ -109,7 +113,7 @@
   ~Transceiver();
 
   /** Start the control loop */
-  bool init(int filler, size_t rtsc, unsigned rach_delay, bool edge);
+  bool init(FillerType filler, size_t rtsc, unsigned rach_delay, bool edge);
 
   /** attach the radioInterface receive FIFO */
   bool receiveFIFO(VectorFIFO *wFIFO, size_t chan)
@@ -143,14 +147,6 @@
 NONE,   ///< Channel is inactive, default
 LOOPBACK///< similar go VII, used in loopback testing
   } ChannelCombination;
-
-  enum FillerType {
-FILLER_DUMMY,
-FILLER_ZERO,
-FILLER_NORM_RAND,
-FILLER_EDGE_RAND,
-FILLER_ACCESS_RAND,
-  };
 
 private:
   int mBasePort;
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index e8bd81a..620c996 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -91,7 +91,7 @@
unsigned rach_delay;
bool extref;
bool gpsref;
-   Transceiver::FillerType filler;
+   FillerType filler;
bool mcbts;
double offset;
double rssi_offset;
@@ -140,19 +140,19 @@
refstr = "Internal";
 

osmo-trx[master]: Logger: Use libosmocore logging system

2018-02-21 Thread Pau Espin Pedrol

Patch Set 4:

(2 comments)

Re: testing again here:

It still makes sense to check logging here as it uses this Log class on top, 
which adds locking mechanism.

https://gerrit.osmocom.org/#/c/6620/4/CommonLibs/Makefile.am
File CommonLibs/Makefile.am:

Line 26: AM_CFLAGS = $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) 
$(LIBOSMOVTY_CFLAGS)
> We already have both VTY and CTRL cflags here,
Yes, as we apply them for C files and for CPP files. In this commit I start 
using libosmocore in cpp files in this directory, that's why it's needed.


https://gerrit.osmocom.org/#/c/6620/4/tests/CommonLibs/Makefile.am
File tests/CommonLibs/Makefile.am:

Line 4: AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOCTRL_LIBS) $(LIBOSMOVTY_LIBS)
> The same question here...
Same answer.


-- 
To view, visit https://gerrit.osmocom.org/6620
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I30baac89f53e927f8699d0586b43cccf88ecd493
Gerrit-PatchSet: 4
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


osmo-bts[master]: RSL: Ensure we don't accept DCHAN messages for CCHAN

2018-02-21 Thread Harald Welte

Patch Set 1: Code-Review+2

(1 comment)

https://gerrit.osmocom.org/#/c/6635/1/src/common/rsl.c
File src/common/rsl.c:

Line 139: static bool chan_nr_is_dchan(uint8_t chan_nr)
> Why not to use a macros here?
what's wrong with a function? it gets inlined by the compiler anyway...


-- 
To view, visit https://gerrit.osmocom.org/6635
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I43a78bec63aeb36dd67043d237b27fe880209349
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


osmo-bts[master]: RSL: Ensure we don't accept DCHAN messages for CCHAN

2018-02-21 Thread Vadim Yanitskiy

Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/6635/1/src/common/rsl.c
File src/common/rsl.c:

Line 139: static bool chan_nr_is_dchan(uint8_t chan_nr)
Why not to use a macros here?

#define CHAN_NR_IS_DCHAN(chan) \
(chan & 0x80)


-- 
To view, visit https://gerrit.osmocom.org/6635
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I43a78bec63aeb36dd67043d237b27fe880209349
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy 
Gerrit-HasComments: Yes


[MERGED] osmo-ttcn3-hacks[master]: RSL_Emulation: Pass ASP_IPA_EVENT_UP to RSL_CCHAN port

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: RSL_Emulation: Pass ASP_IPA_EVENT_UP to RSL_CCHAN port
..


RSL_Emulation: Pass ASP_IPA_EVENT_UP to RSL_CCHAN port

When emulating the BSC side of RSL, this can be used by a test case
to wait for the RSL connection to be established.

Change-Id: Iad2f6e4cb6a8f3b77e452f36a83ec11e7554e6c7
---
M library/RSL_Emulation.ttcn
1 file changed, 6 insertions(+), 2 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/library/RSL_Emulation.ttcn b/library/RSL_Emulation.ttcn
index 5c7dc9c..bf6686a 100644
--- a/library/RSL_Emulation.ttcn
+++ b/library/RSL_Emulation.ttcn
@@ -53,7 +53,7 @@
 } with { extension "internal" };
 
 type port RSL_CCHAN_PT message {
-   inout ASP_RSL_Unitdata;
+   inout ASP_RSL_Unitdata, ASP_IPA_Event;
 } with { extension "internal" };
 
 
@@ -277,6 +277,7 @@
 
 
 function main(boolean bts_role := true) runs on RSL_Emulation_CT {
+   var ASP_IPA_Event evt;
var ASP_RSL_Unitdata rx_rsl;
var RSL_Message rx_rsl_msg;
var RSLDC_ChanRqd chan_rqd;
@@ -292,7 +293,10 @@
 
while (true) {
alt {
-   [] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) {
+   [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_UP}) {
+   }
+   [not bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_UP}) -> value evt {
+   CCHAN_PT.send(evt);
}
[bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_ID_ACK}) {

IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));

-- 
To view, visit https://gerrit.osmocom.org/6628
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iad2f6e4cb6a8f3b77e452f36a83ec11e7554e6c7
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


[MERGED] osmo-ttcn3-hacks[master]: RSL_Emulation: Introduce notion of 'bts_role'

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: RSL_Emulation: Introduce notion of 'bts_role'
..


RSL_Emulation: Introduce notion of 'bts_role'

So far we assumed we emulate the BTS side and talk to a BSC.

Let's make this configurable and disable the BTS-side spcific code
paths by means of a 'bts_role' boolean type.

Change-Id: I0d0460cbb633b470f6117d07643f68aefb1530eb
---
M library/RSL_Emulation.ttcn
1 file changed, 20 insertions(+), 8 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/library/RSL_Emulation.ttcn b/library/RSL_Emulation.ttcn
index dab1785..5c7dc9c 100644
--- a/library/RSL_Emulation.ttcn
+++ b/library/RSL_Emulation.ttcn
@@ -52,6 +52,11 @@
inout RSLDC_ChanRqd, RSL_Message;
 } with { extension "internal" };
 
+type port RSL_CCHAN_PT message {
+   inout ASP_RSL_Unitdata;
+} with { extension "internal" };
+
+
 signature RSLEM_register(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr 
hdlr);
 signature RSLEM_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr 
hdlr);
 signature RSLEM_suspend(boolean suspend);
@@ -242,6 +247,9 @@
port RSL_DCHAN_PT CLIENT_PT;
port RSLEM_PROC_PT RSL_PROC;
 
+   /* port for Common Channel / TRX Management */
+   port RSL_CCHAN_PT CCHAN_PT;
+
/* state of all concurrent connections / dedicated channels */
var ConnectionData ConnectionTable[64];
 }
@@ -268,7 +276,7 @@
 }
 
 
-function main() runs on RSL_Emulation_CT {
+function main(boolean bts_role := true) runs on RSL_Emulation_CT {
var ASP_RSL_Unitdata rx_rsl;
var RSL_Message rx_rsl_msg;
var RSLDC_ChanRqd chan_rqd;
@@ -286,10 +294,10 @@
alt {
[] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) {
}
-   [] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_ID_ACK}) {
+   [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := 
ASP_IPA_EVENT_ID_ACK}) {

IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
}
-   [] IPA_PT.receive(tr_RSL(tr_RSL_IMM_ASSIGN)) -> value rx_rsl {
+   [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_IMM_ASSIGN)) -> value 
rx_rsl {
var GsmRrMessage rr;
var OCT1 ra;
var GsmFrameNumber fn;
@@ -327,7 +335,7 @@
}
}
 
-   [] IPA_PT.receive(tr_RSL(tr_RSL_PAGING_CMD(?, ?))) -> value 
rx_rsl {
+   [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_PAGING_CMD(?, ?))) -> 
value rx_rsl {
log("PAGING IDENTITY ", rx_rsl.rsl.ies[2].body.other);
/* broadcast to all clients? */
for (i := 0; i < sizeof(ConnectionTable); i := i + 1) {
@@ -337,16 +345,20 @@
}
}
 
+   /* Forward common channel management to the special port for it 
*/
[] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeT(?))) -> value rx_rsl {
-   log("Ingnoring TRX Mgmt ", rx_rsl.rsl);
+   log("Forwarding TRX Mgmt ", rx_rsl.rsl);
+   CCHAN_PT.send(rx_rsl);
}
 
+   /* Forward common channel management to the special port for it 
*/
[] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeC(?))) -> value rx_rsl {
-   log("Ignoring Common Channel Mgmt ", rx_rsl.rsl);
+   log("Forwarding Common Channel Mgmt ", rx_rsl.rsl);
+   CCHAN_PT.send(rx_rsl);
}
 
/* blindly acknowledge all channel activations */
-   [] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) 
-> value rx_rsl {
+   [bts_role] 
IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) -> value rx_rsl {
chan_nr := rx_rsl.rsl.ies[0].body.chan_nr;
IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.streamId, 
ts_RSL_CHAN_ACT_ACK(chan_nr, 23)));
}
@@ -367,7 +379,7 @@
self.stop;
}
 
-   [] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender 
vc_conn {
+   [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd 
sender vc_conn {
/* Store the knowledge that this sender has requested a 
certain RQ+time */
f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn);
IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,

-- 
To view, visit https://gerrit.osmocom.org/6627
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0d0460cbb633b470f6117d07643f68aefb1530eb
Gerrit-PatchSet: 1
Gerrit-Project:

[MERGED] osmo-ttcn3-hacks[master]: IPA_Emulation: Don't log IPAC_MSGT_ID_RESP as "Unknown/unsup...

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: IPA_Emulation: Don't log IPAC_MSGT_ID_RESP as 
"Unknown/unsupported"
..


IPA_Emulation: Don't log IPAC_MSGT_ID_RESP as "Unknown/unsupported"

Change-Id: I6ea3855a1f3d1cba6ac173b0f9cf9052d5d028fc
---
M library/IPA_Emulation.ttcnpp
1 file changed, 3 insertions(+), 0 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/library/IPA_Emulation.ttcnpp b/library/IPA_Emulation.ttcnpp
index 3508091..c3cfe8d 100644
--- a/library/IPA_Emulation.ttcnpp
+++ b/library/IPA_Emulation.ttcnpp
@@ -342,6 +342,9 @@
case (IPAC_MSGT_ID_GET) {
f_ccm_tx(f_ccm_make_id_resp(ccm));
}
+   case (IPAC_MSGT_ID_RESP) {
+   log("IPA ID RESP: ", ccm.u.resp);
+   }
case else {
log("Unknown/unsupported IPA CCM message type", ccm);
}

-- 
To view, visit https://gerrit.osmocom.org/6626
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6ea3855a1f3d1cba6ac173b0f9cf9052d5d028fc
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


[MERGED] osmo-ttcn3-hacks[master]: IPA_Emulation: Make dependencies to RSL/MGCP/SCCP/GSUP condi...

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: IPA_Emulation: Make dependencies to RSL/MGCP/SCCP/GSUP 
conditional
..


IPA_Emulation: Make dependencies to RSL/MGCP/SCCP/GSUP conditional

Let's use the preprocessor to avoid IPA_Emulation pulling *all*
dependencies into each and any of our projects.  The code readability
suffers a bit from the many #ifdefs, but compilation speed increases
if we don't have to pull in all those (recursive) dependencies.

After all, a BTS test case will never need SCCP, GSUP or MGCP.

Change-Id: Ic0231adbd2171214de133d26b3fbf36130ee8aa0
---
M bsc-nat/gen_links.sh
M bsc-nat/regen_makefile.sh
M bsc/gen_links.sh
M bsc/regen_makefile.sh
D hlr/Makefile
M hlr/gen_links.sh
M hlr/regen_makefile.sh
R library/IPA_Emulation.ttcnpp
M msc/gen_links.sh
M msc/regen_makefile.sh
M regen-makefile.sh
M selftest/Selftest.ttcn
M selftest/gen_links.sh
M selftest/regen_makefile.sh
M sgsn/gen_links.sh
M sgsn/regen_makefile.sh
16 files changed, 130 insertions(+), 267 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/bsc-nat/gen_links.sh b/bsc-nat/gen_links.sh
index d27c092..e9280e6 100755
--- a/bsc-nat/gen_links.sh
+++ b/bsc-nat/gen_links.sh
@@ -55,5 +55,5 @@
 gen_links $DIR $FILES
 
 DIR=../library
-FILES="General_Types.ttcn Osmocom_Types.ttcn GSM_Types.ttcn IPA_Types.ttcn 
IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn IPA_CodecPort_CtrlFunctDef.cc 
IPA_Emulation.ttcn L3_Templates.ttcn BSSMAP_Templates.ttcn 
BSSMAP_Emulation.ttcn MGCP_Types.ttcn MGCP_Templates.ttcn MGCP_CodecPort.ttcn 
MGCP_CodecPort_CtrlFunct.ttcn MGCP_CodecPort_CtrlFunctDef.cc RSL_Types.ttcn 
Osmocom_CTRL_Types.ttcn Osmocom_CTRL_Functions.ttcn BSSAP_CodecPort.ttcn 
GSUP_Types.ttcn"
+FILES="General_Types.ttcn Osmocom_Types.ttcn GSM_Types.ttcn IPA_Types.ttcn 
IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn IPA_CodecPort_CtrlFunctDef.cc 
IPA_Emulation.ttcnpp L3_Templates.ttcn BSSMAP_Templates.ttcn 
BSSMAP_Emulation.ttcn MGCP_Types.ttcn MGCP_Templates.ttcn MGCP_CodecPort.ttcn 
MGCP_CodecPort_CtrlFunct.ttcn MGCP_CodecPort_CtrlFunctDef.cc 
Osmocom_CTRL_Types.ttcn Osmocom_CTRL_Functions.ttcn BSSAP_CodecPort.ttcn"
 gen_links $DIR $FILES
diff --git a/bsc-nat/regen_makefile.sh b/bsc-nat/regen_makefile.sh
index a3c6243..3d17cfe 100755
--- a/bsc-nat/regen_makefile.sh
+++ b/bsc-nat/regen_makefile.sh
@@ -2,6 +2,8 @@
 
 MAIN=IPA_Test.ttcn
 
-FILES="*.ttcn SCCP_EncDec.cc IPA_CodecPort_CtrlFunctDef.cc IPL4asp_PT.cc 
IPL4asp_discovery.cc TCCConversion.cc TCCInterface.cc RTP_EncDec.cc 
SDP_EncDec.cc *.c MGCP_CodecPort_CtrlFunctDef.cc"
+FILES="*.ttcn *.ttcnpp SCCP_EncDec.cc IPA_CodecPort_CtrlFunctDef.cc 
IPL4asp_PT.cc IPL4asp_discovery.cc TCCConversion.cc TCCInterface.cc 
RTP_EncDec.cc SDP_EncDec.cc *.c MGCP_CodecPort_CtrlFunctDef.cc"
+
+export CPPFLAGS_TTCN3="-DIPA_EMULATION_SCCP -DIPA_EMULATION_MGCP"
 
 ../regen-makefile.sh $MAIN $FILES
diff --git a/bsc/gen_links.sh b/bsc/gen_links.sh
index c80ae64..a173aac 100755
--- a/bsc/gen_links.sh
+++ b/bsc/gen_links.sh
@@ -80,5 +80,5 @@
 gen_links $DIR $FILES
 
 DIR=../library
-FILES="General_Types.ttcn Osmocom_Types.ttcn GSM_Types.ttcn 
Osmocom_VTY_Functions.ttcn Native_Functions.ttcn Native_FunctionDefs.cc 
IPA_Types.ttcn IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn 
IPA_CodecPort_CtrlFunctDef.cc IPA_Emulation.ttcn L3_Templates.ttcn 
BSSMAP_Templates.ttcn BSSMAP_Emulation.ttcn RLCMAC_CSN1_Types.ttcn 
GSM_RR_Types.ttcn RSL_Types.ttcn RSL_Emulation.ttcn MGCP_Emulation.ttcn 
MGCP_Types.ttcn MGCP_Templates.ttcn MGCP_CodecPort.ttcn 
MGCP_CodecPort_CtrlFunct.ttcn MGCP_CodecPort_CtrlFunctDef.cc 
BSSAP_CodecPort.ttcn BSSAP_Adapter.ttcn Osmocom_CTRL_Types.ttcn 
Osmocom_CTRL_Functions.ttcn Osmocom_CTRL_Adapter.ttcn RTP_CodecPort.ttcn 
RTP_CodecPort_CtrlFunct.ttcn RTP_CodecPort_CtrlFunctDef.cc RTP_Emulation.ttcn 
IuUP_Types.ttcn IuUP_EncDec.cc IuUP_Emulation.ttcn GSUP_Types.ttcn"
+FILES="General_Types.ttcn Osmocom_Types.ttcn GSM_Types.ttcn 
Osmocom_VTY_Functions.ttcn Native_Functions.ttcn Native_FunctionDefs.cc 
IPA_Types.ttcn IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn 
IPA_CodecPort_CtrlFunctDef.cc IPA_Emulation.ttcnpp L3_Templates.ttcn 
BSSMAP_Templates.ttcn BSSMAP_Emulation.ttcn RLCMAC_CSN1_Types.ttcn 
GSM_RR_Types.ttcn RSL_Types.ttcn RSL_Emulation.ttcn MGCP_Emulation.ttcn 
MGCP_Types.ttcn MGCP_Templates.ttcn MGCP_CodecPort.ttcn 
MGCP_CodecPort_CtrlFunct.ttcn MGCP_CodecPort_CtrlFunctDef.cc 
BSSAP_CodecPort.ttcn BSSAP_Adapter.ttcn Osmocom_CTRL_Types.ttcn 
Osmocom_CTRL_Functions.ttcn Osmocom_CTRL_Adapter.ttcn RTP_CodecPort.ttcn 
RTP_CodecPort_CtrlFunct.ttcn RTP_CodecPort_CtrlFunctDef.cc RTP_Emulation.ttcn 
IuUP_Types.ttcn IuUP_EncDec.cc IuUP_Emulation.ttcn "
 gen_links $DIR $FILES
diff --git a/bsc/regen_makefile.sh b/bsc/regen_makefile.sh
index 0b8e1fa..e9eb808 100755
--- a/bsc/regen_makefile.sh
+++ b/bsc/regen_makefile.sh
@@ -2,6 +2,8 @@
 
 MAIN=BSC_T

[MERGED] osmo-ttcn3-hacks[master]: RSL_Types: Add templates for "BSC side"

2018-02-21 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: RSL_Types: Add templates for "BSC side"
..


RSL_Types: Add templates for "BSC side"

So far, the RSL templates have been used for BSC testing, i.e.
TTCN3 behaving like a BTS.  Now we want to test the BTS, so we
have to "invert" the receive/send direction and hence also need
the inverse templates.

This doesn't add *all* of them, but a sufficiently large number for our
first testcases against OsmoBTS.

Change-Id: Ica9cfae5a691e4d967d046b04e5bb16a71a89adf
---
M library/RSL_Types.ttcn
1 file changed, 211 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/library/RSL_Types.ttcn b/library/RSL_Types.ttcn
index 765a91e..b1716fd 100644
--- a/library/RSL_Types.ttcn
+++ b/library/RSL_Types.ttcn
@@ -405,10 +405,24 @@
t2 := fn mod 26
}
 
+   function tr_RSL_IE_FrameNumber(template GsmFrameNumber fn) return 
template RSL_IE_FrameNumber {
+   if (istemplatekind(fn, "?")) {
+   return ?;
+   } else {
+   return ts_RSL_IE_FrameNumber(valueof(fn));
+   }
+   }
+
template RSL_IE_RequestRef ts_RSL_IE_ReqRef(OCT1 ra, GsmFrameNumber 
frame_nr) := {
ra := ra,
frame_nr := ts_RSL_IE_FrameNumber(frame_nr)
}
+
+   template RSL_IE_RequestRef tr_RSL_IE_ReqRef(template OCT1 ra, template 
GsmFrameNumber frame_nr) := {
+   ra := ra,
+   frame_nr := tr_RSL_IE_FrameNumber(frame_nr)
+   }
+
 
/* 9.3.26 */
type enumerated RSL_Cause {
@@ -463,6 +477,13 @@
 
template RSL_IE_Cause ts_RSL_IE_Cause(RSL_Cause cause) := {
len := 0, /* overwritten */
+   e := 0,
+   cause := cause,
+   cause_ext := omit
+   }
+
+   template RSL_IE_Cause tr_RSL_IE_Cause(template RSL_Cause cause) := {
+   len := ?,
e := 0,
cause := cause,
cause_ext := omit
@@ -749,6 +770,16 @@
t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := 
ts_RSL_L16V(l3_info)})
}
}
+   template RSL_Message tr_RSL_DATA_IND(template RslChannelNr chan_nr, 
template RslLinkId link_id,
+template octetstring l3_info := ?) 
:= {
+   msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, true),
+   msg_type := RSL_MT_DATA_IND,
+   ies :={
+   tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
+   tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
+   tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
+   }
+   }
 
/* 8.3.3 BTS -> BSC */
template RSL_Message ts_RSL_ERROR_IND(RslChannelNr chan_nr, RslLinkId 
link_id, RSL_Cause cause) := {
@@ -760,6 +791,16 @@
t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := 
ts_RSL_IE_Cause(cause)})
}
}
+   template RSL_Message tr_RSL_ERROR_IND(template RslChannelNr chan_nr, 
template RslLinkId link_id,
+   template RSL_Cause cause := ?) 
:= {
+   msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
+   msg_type := RSL_MT_ERROR_IND,
+   ies :={
+   tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
+   tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
+   tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
+   }
+   }
 
/* 8.3.6 BTS -> BSC */
template RSL_Message ts_RSL_EST_IND(RslChannelNr chan_nr, RslLinkId 
link_id, octetstring l3_info) := {
@@ -769,6 +810,16 @@
t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := 
chan_nr}),
t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := 
link_id}),
t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := 
ts_RSL_L16V(l3_info)})
+   }
+   }
+   template RSL_Message tr_RSL_EST_IND(template RslChannelNr chan_nr, 
template RslLinkId link_id,
+   template octetstring l3_info := 
?) := {
+   msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
+   msg_type := RSL_MT_EST_IND,
+   ies := {
+   tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
+   tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
+   tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
}
}
 
@@ -801,6 +852,14 @@
t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := 
link_id})
}
}
+   template RSL_Message tr_RSL_REL_CONF(template RslChannelNr

[PATCH] osmo-ttcn3-hacks[master]: L1CTL: Add optional link_id argument to t_L1CTL_DATA_IND()

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6652

L1CTL: Add optional link_id argument to t_L1CTL_DATA_IND()

Change-Id: Ib4cf42825da1034966086d9232273c2328a94947
---
M library/L1CTL_Types.ttcn
1 file changed, 4 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/52/6652/1

diff --git a/library/L1CTL_Types.ttcn b/library/L1CTL_Types.ttcn
index 00323b4..d49f37d 100644
--- a/library/L1CTL_Types.ttcn
+++ b/library/L1CTL_Types.ttcn
@@ -501,12 +501,13 @@
payload := ?
};
 
-   /* for matching against incoming RACH_CONF */
-   template L1ctlDlMessage t_L1CTL_DATA_IND(template RslChannelNr chan_nr) 
:= {
+   /* for matching against incoming DATA_IND */
+   template L1ctlDlMessage t_L1CTL_DATA_IND(template RslChannelNr chan_nr,
+template RslLinkId link_id := 
?) := {
header := t_L1ctlHeader(L1CTL_DATA_IND),
dl_info := {
chan_nr := chan_nr,
-   link_id := ?,
+   link_id := link_id,
arfcn := ?,
frame_nr := ?,
rx_level := ?,

-- 
To view, visit https://gerrit.osmocom.org/6652
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4cf42825da1034966086d9232273c2328a94947
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Owner: Harald Welte 


[PATCH] osmo-ttcn3-hacks[master]: GSM_RR_Types: Add ts_IMM_ASS and ts_MEAS_REP

2018-02-21 Thread Harald Welte

Review at  https://gerrit.osmocom.org/6653

GSM_RR_Types: Add ts_IMM_ASS and ts_MEAS_REP

which allows us to send RR IMMEDIATE ASSIGNMENT (DL/AGCH) and
RR MEASUREMENT REPORT (UL/SACCH) messages from tests.

Change-Id: Ic75041e84c15c77805ecafb823bf7108920675ca
---
M library/GSM_RR_Types.ttcn
1 file changed, 92 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/53/6653/1

diff --git a/library/GSM_RR_Types.ttcn b/library/GSM_RR_Types.ttcn
index eed58df..2625a1f 100644
--- a/library/GSM_RR_Types.ttcn
+++ b/library/GSM_RR_Types.ttcn
@@ -139,6 +139,12 @@
RrMessageType   message_type
} with { variant "" };
 
+   template RrL3Header t_RrL3Header(RrMessageType msg_type) := {
+   skip_indicator := 0,
+   rr_protocol_discriminator := 6,
+   message_type := msg_type
+   }
+
type record MaioHsn {
} with { variant "" };
 
@@ -486,6 +492,31 @@
variant (hh) "PRESENCE(presence = '11'B)"
};
 
+   type record MeasurementResults {
+   BIT1ba_used,
+   BIT1dtx_used,
+   uint6_t rxlev_full_srv_cell,
+   BIT1threeg_ba_used,
+   BIT1meas_valid,
+   uint6_t rxlev_sub_srv_cell,
+   BIT1si23_ba_used,
+   uint3_t rxqual_full_srv_cell,
+   uint3_t rxqual_sub_srv_cell,
+   uint3_t no_ncell_m,
+   NcellReportsncell_reports optional
+   } with { variant (no_ncell_m) "LENGTHTO(ncell_reports)"
+variant (no_ncell_m) "UNIT(elements)"
+variant "PADDING(yes)"
+variant "FIELDLENGTH(16)"
+   };
+
+   type record NcellReport {
+   uint6_t rxlev,
+   uint5_t bcch_freq,
+   uint6_t bsic
+   } with { variant ""};
+   type record of NcellReport NcellReports;
+
 
/* 9.1.18 */
type record ImmediateAssignment {
@@ -497,7 +528,7 @@
TimingAdvance   timing_advance,
MobileAllocationmobile_allocation,
/* TODO: starting time TLV */
-   IaRestOctetsrest_octets
+   IaRestOctetsrest_octets optional
} with { variant (chan_desc) "PRESENCE(ded_or_tbf.tbf = false)"
 variant (pkt_chan_desc) "PRESENCE(ded_or_tbf.tbf = true)" };
 
@@ -511,6 +542,11 @@
FeatureIndicatorfeature_ind,
PageModepage_mode,
ReqRefWaitInd4  payload
+   } with { variant "" };
+
+   /* 9.1.21 */
+   type record MeasurementReport {
+   MeasurementResults  meas_res
} with { variant "" };
 
/* 9.1.22 */
@@ -607,6 +643,7 @@
 
type union RrL3Union {
PagingResponse  paging_response,
+   MeasurementReport meas_rep,
octetstring other
};
 
@@ -615,8 +652,61 @@
RrL3Union   payload
} with { variant (payload) "CROSSTAG(
paging_response, header.message_type = 
PAGING_RESPONSE;
-
+   meas_rep, header.message_type = 
MEASUREMENT_REPORT;
other, OTHERWISE;
)" }
 
+   external function enc_GsmRrL3Message(in GsmRrL3Message msg) return 
octetstring
+   with { extension "prototype(convert) encode(RAW)" };
+   external function dec_GsmRrL3Message(in octetstring stream) return 
GsmRrL3Message
+   with { extension "prototype(convert) decode(RAW)" };
+
+
+   template GsmRrMessage ts_IMM_ASS(uint8_t ra, GsmFrameNumber fn, 
TimingAdvance ta,
+   ChannelDescription ch_desc, 
MobileAllocation ma) := {
+   header := t_RrHeader(IMMEDIATE_ASSIGNMENT, 0),
+   payload := {
+   imm_ass := {
+   ded_or_tbf := {
+   spare := '0'B,
+   tma := false,
+   downlink := false,
+   tbf := false
+   },
+   page_mode := PAGE_MODE_NORMAL,
+   chan_desc := ch_desc,
+   pkt_chan_desc := omit,
+   req_ref := f_compute_ReqRef(ra, fn),
+   timing_advance := ta,
+   mobile_allocation := ma,
+   rest_octets := omit
+   }
+   }
+   };
+
+   template (v

[PATCH] libosmocore[master]: cosmetic: gsm0408_test: RA test cases as array-of-struct

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6654

cosmetic: gsm0408_test: RA test cases as array-of-struct

(Preparation for adding 3-digit MNC)

Change-Id: Ic6c645ebf82d5f8d9d51c4c4cc804a0172008156
---
M tests/gsm0408/gsm0408_test.c
1 file changed, 12 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/54/6654/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index ab2dee4..8e6cf2f 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -158,23 +158,27 @@
printf("passed\n");
 }
 
-static void test_ra_cap(void)
-{
-   struct gprs_ra_id raid1 = {
+static struct gprs_ra_id test_ra_cap_items[] = {
+   {
.mnc = 121,
.mcc = 77,
.lac = 666,
.rac = 5,
-   };
-   struct gprs_ra_id raid2 = {
+   },
+   {
.mnc = 98,
.mcc = 84,
.lac = 11,
.rac = 89,
-   };
+   },
+};
 
-   check_ra(&raid1);
-   check_ra(&raid2);
+static void test_ra_cap(void)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(test_ra_cap_items); i++)
+   check_ra(&test_ra_cap_items[i]);
 }
 
 static void test_mid_from_tmsi(void)

-- 
To view, visit https://gerrit.osmocom.org/6654
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic6c645ebf82d5f8d9d51c4c4cc804a0172008156
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] libosmocore[master]: gsm0408_test: cosmetically re-order MCC to come before MNC

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6655

gsm0408_test: cosmetically re-order MCC to come before MNC

For consistency in human readability, MCC simply should come first, always.

Change-Id: Idb86a7088fac4d8a8c41190ab46f9801635f4eee
---
M tests/gsm0408/gsm0408_test.c
M tests/gsm0408/gsm0408_test.ok
2 files changed, 7 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/55/6655/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index 8e6cf2f..87f8dde 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -132,7 +132,7 @@
 
 static inline void dump_ra(const struct gprs_ra_id *raid)
 {
-   printf("RA: MNC=%u, MCC=%u, LAC=%u, RAC=%u\n", raid->mnc, raid->mcc, 
raid->lac, raid->rac);
+   printf("RA: MCC=%u, MNC=%u, LAC=%u, RAC=%u\n", raid->mcc, raid->mnc, 
raid->lac, raid->rac);
 }
 
 static inline void check_ra(const struct gprs_ra_id *raid)
@@ -160,14 +160,14 @@
 
 static struct gprs_ra_id test_ra_cap_items[] = {
{
-   .mnc = 121,
.mcc = 77,
+   .mnc = 121,
.lac = 666,
.rac = 5,
},
{
-   .mnc = 98,
.mcc = 84,
+   .mnc = 98,
.lac = 11,
.rac = 89,
},
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index 76a7940..295d8ec 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -3,10 +3,10 @@
 Simple TMSI encoding testpassed
 Simple IMSI encoding testpassed: [10] 17 08 99 10 07 00 00 00 64 02 
 Constructed RA:
-RA: MNC=121, MCC=77, LAC=666, RAC=5
-RA: MNC=121, MCC=77, LAC=666, RAC=5
+RA: MCC=77, MNC=121, LAC=666, RAC=5
+RA: MCC=77, MNC=121, LAC=666, RAC=5
 RA test...passed
 Constructed RA:
-RA: MNC=98, MCC=84, LAC=11, RAC=89
-RA: MNC=98, MCC=84, LAC=11, RAC=89
+RA: MCC=84, MNC=98, LAC=11, RAC=89
+RA: MCC=84, MNC=98, LAC=11, RAC=89
 RA test...passed

-- 
To view, visit https://gerrit.osmocom.org/6655
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb86a7088fac4d8a8c41190ab46f9801635f4eee
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] libosmocore[master]: gsm0408_test: include BCD and leading zeros in test output

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6656

gsm0408_test: include BCD and leading zeros in test output

(Preparation for adding 3-digit MNC)

Change-Id: I7f8ae05fa3e4a6fc004212757b05ca8a14c9ef45
---
M tests/gsm0408/gsm0408_test.c
M tests/gsm0408/gsm0408_test.ok
2 files changed, 8 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/56/6656/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index 87f8dde..aa6a8be 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -132,7 +132,7 @@
 
 static inline void dump_ra(const struct gprs_ra_id *raid)
 {
-   printf("RA: MCC=%u, MNC=%u, LAC=%u, RAC=%u\n", raid->mcc, raid->mnc, 
raid->lac, raid->rac);
+   printf("%03u-%02u-%u-%u\n", raid->mcc, raid->mnc, raid->lac, raid->rac);
 }
 
 static inline void check_ra(const struct gprs_ra_id *raid)
@@ -150,6 +150,7 @@
 
gsm48_parse_ra(&raid0, (const uint8_t *)&ra);
dump_ra(raid);
+   printf("MCC+MNC in BCD: %s\n", osmo_hexdump(ra.digits, 
sizeof(ra.digits)));
dump_ra(&raid0);
printf("RA test...");
if (raid->mnc != raid0.mnc || raid->mcc != raid0.mcc || raid->lac != 
raid0.lac || raid->rac != raid0.rac)
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index 295d8ec..a3d801d 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -3,10 +3,12 @@
 Simple TMSI encoding testpassed
 Simple IMSI encoding testpassed: [10] 17 08 99 10 07 00 00 00 64 02 
 Constructed RA:
-RA: MCC=77, MNC=121, LAC=666, RAC=5
-RA: MCC=77, MNC=121, LAC=666, RAC=5
+077-121-666-5
+MCC+MNC in BCD: 70 17 21 
+077-121-666-5
 RA test...passed
 Constructed RA:
-RA: MCC=84, MNC=98, LAC=11, RAC=89
-RA: MCC=84, MNC=98, LAC=11, RAC=89
+084-98-11-89
+MCC+MNC in BCD: 80 f4 89 
+084-98-11-89
 RA test...passed

-- 
To view, visit https://gerrit.osmocom.org/6656
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f8ae05fa3e4a6fc004212757b05ca8a14c9ef45
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] libosmocore[master]: implement support for 3-digit MNC with leading zeros

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6659

implement support for 3-digit MNC with leading zeros

Enable representing three-digit MNC with leading zeros. The MNCs 23 and 023 are
actually different; so far we treated both as 23. Re-encode an incoming BCD or
string of 023 as it were, i.e. not dropping the leading zero as 23.

Break ABI compatibility by changing the size and ordering of struct gprs_ra_id.
Ordering is changed because the canonical oder is {Mobile Country Code, Mobile
Network Code}, so have the mcc member first. Change size (and ordering) by
inserting a flag to indicate a three-digit MNC after the mnc member. ABI
compatibility cannot be maintained, since struct gprs_ra_id is a direct member
of structs bssgp_bvc_ctx and bssgp_paging_info, and even just adding a flag to
the end would cause ABI changes of those structs.

Add new API to set and read this additional flag to preserve leading zeros:
- gsm48_mcc_mnc_to_bcd2(), gsm48_mcc_mnc_from_bcd2() after
  gsm48_mcc_mnc_to_bcd() and gsm48_mcc_mnc_from_bcd().
- gsm0808_create_layer3_aoip2() after gsm0808_create_layer3_aoip().
- gsm48_decode_lai2(), gsm48_generate_lai2() after
  gsm48_decode_lai(), gsm48_generate_lai().
- The equivalent of gsm0808_create_layer3() for preserving leading zeros is
  gsm0808_create_layer3_aoip2() with the scl argument passed as NULL; instead
  of introducing a new shim function like gsm0808_create_layer3_2(), indicate
  such in the API docs, only.
- gsm48_mnc_from_str() to encode leading zeros from string, useful for VTY
  config parsing.
- gsm48_mnc_cmp() to compare MNC values including leading zeros.

In various log output, include the leading MNC zeros.

Mark one TODO in card_fs_sim.c, I am not sure how to communicate a leading zero
to/from a SIM card FS. The focus here is on the core network / BSS.

To indicate ABI incompatibility, bump libosmogsm and libosmogb LIBVERSIONs;
adjust debian files accordingly.

Implementation choices:

- The default behavior upon zero-initialization will be the mnc_3_digits flag
  set to false, which yields exactly the previous behavior.

- I decided against packing the mnc with the mnc_3_digits field into a
  sub-struct because it would enlarge this patch; plus, with a separate flag,
  current code can decide when to start heeding leading zeros.

Change-Id: Id2240f7f518494c9df6c8bda52c0d5092f90f221
---
M debian/control
R debian/libosmogb6.install
R debian/libosmogsm9.install
M include/osmocom/gsm/gsm0808.h
M include/osmocom/gsm/gsm23003.h
M include/osmocom/gsm/gsm48.h
M src/gb/Makefile.am
M src/gb/gprs_bssgp.c
M src/gb/gprs_bssgp_vty.c
M src/gsm/Makefile.am
M src/gsm/gsm0808.c
M src/gsm/gsm48.c
M src/gsm/libosmogsm.map
M src/sim/card_fs_sim.c
14 files changed, 234 insertions(+), 40 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/59/6659/1

diff --git a/debian/control b/debian/control
index 596c3f1..d911f32 100644
--- a/debian/control
+++ b/debian/control
@@ -28,8 +28,8 @@
 Depends: libosmocodec0 (= ${binary:Version}),
  libosmocoding0 (= ${binary:Version}),
  libosmocore9 (= ${binary:Version}),
- libosmogb5 (= ${binary:Version}),
- libosmogsm8 (= ${binary:Version}),
+ libosmogb6 (= ${binary:Version}),
+ libosmogsm9 (= ${binary:Version}),
  libosmovty4 (= ${binary:Version}),
  libosmoctrl1 (= ${binary:Version}),
  libosmosim0 (= ${binary:Version}),
@@ -146,7 +146,7 @@
  .
  This package contains the documentation for the libosmocore library.
 
-Package: libosmogb5
+Package: libosmogb6
 Section: libs
 Architecture: any
 Multi-Arch: same
@@ -167,7 +167,7 @@
 Architecture: all
 Section: doc
 Depends: ${misc:Depends},
- libosmogb5,
+ libosmogb6,
  libjs-jquery
 Description: Documentation for the Osmo GPRS Gb library
  This is part of the libosmocore "meta"-library. The libosmocore library
@@ -178,7 +178,7 @@
  .
  This package contains the documentation for the libosmogb library.
 
-Package: libosmogsm8
+Package: libosmogsm9
 Section: libs
 Architecture: any
 Multi-Arch: same
@@ -202,7 +202,7 @@
 Architecture: all
 Section: doc
 Depends: ${misc:Depends},
- libosmogsm8,
+ libosmogsm9,
  libjs-jquery
 Description: Documentation for the Osmo GSM utility library
  This is part of the libosmocore "meta"-library. The libosmocore library
diff --git a/debian/libosmogb5.install b/debian/libosmogb6.install
similarity index 100%
rename from debian/libosmogb5.install
rename to debian/libosmogb6.install
diff --git a/debian/libosmogsm8.install b/debian/libosmogsm9.install
similarity index 100%
rename from debian/libosmogsm8.install
rename to debian/libosmogsm9.install
diff --git a/include/osmocom/gsm/gsm0808.h b/include/osmocom/gsm/gsm0808.h
index 3deee70..f0f8a38 100644
--- a/include/osmocom/gsm/gsm0808.h
+++ b/include/osmocom/gsm/gsm0808.h
@@ -35,6 +35,10 @@
uint16_t cc, int lac, uint16_t _ci,
  

[PATCH] libosmocore[master]: gsm0408_test: add test cases for MNC with leading zeros

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6662

gsm0408_test: add test cases for MNC with leading zeros

Change-Id: I9b387e09293a6bbef84b9620ccf21ee2f9ec751c
---
M tests/gsm0408/gsm0408_test.c
M tests/gsm0408/gsm0408_test.ok
2 files changed, 149 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/62/6662/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index c40c643..2591442 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -233,6 +233,16 @@
.mnc = 0,
.lac = 0,
.rac = 0,
+   .mnc_3_digits = false,
+   /* expecting 000-00, BCD = 00 f0 00 */
+   },
+   {
+   .mcc = 0,
+   .mnc = 0,
+   .lac = 0,
+   .rac = 0,
+   .mnc_3_digits = true,
+   /* expecting 000-000, BCD = 00 00 00 */
},
{
.mcc = 999,
@@ -240,6 +250,54 @@
.lac = 65535,
.rac = 255,
},
+   {
+   .mcc = 1,
+   .mnc = 2,
+   .lac = 23,
+   .rac = 42,
+   .mnc_3_digits = false,
+   /* expecting 001-02, BCD = 00 f1 20 */
+   },
+   {
+   .mcc = 1,
+   .mnc = 2,
+   .lac = 23,
+   .rac = 42,
+   .mnc_3_digits = true,
+   /* expecting 001-002, BCD = 00 21 00 */
+   },
+   {
+   .mcc = 12,
+   .mnc = 34,
+   .lac = 56,
+   .rac = 78,
+   .mnc_3_digits = false,
+   /* expecting 012-34, BCD = 10 f2 43 */
+   },
+   {
+   .mcc = 12,
+   .mnc = 34,
+   .lac = 23,
+   .rac = 42,
+   .mnc_3_digits = true,
+   /* expecting 012-034, BCD = 10 42 30 */
+   },
+   {
+   .mcc = 123,
+   .mnc = 456,
+   .lac = 23,
+   .rac = 42,
+   .mnc_3_digits = false,
+   /* expecting 123-456, BCD = 21 63 54 (false flag has no effect) 
*/
+   },
+   {
+   .mcc = 123,
+   .mnc = 456,
+   .lac = 23,
+   .rac = 42,
+   .mnc_3_digits = true,
+   /* expecting 123-456, BCD = 21 63 54 (same) */
+   },
 };
 
 static void test_ra_cap(void)
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index be2a1de..59484c3 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -18,9 +18,44 @@
 000-00-0-0
 RA test...passed
 Constructed RA:
+000-000-0-0 (3-digit MNC)
+MCC+MNC in BCD: 00 00 00 
+000-000-0-0 (3-digit MNC)
+RA test...passed
+Constructed RA:
 999-999-65535-255
 MCC+MNC in BCD: 99 99 99 
 999-999-65535-255 (3-digit MNC)
+RA test...passed
+Constructed RA:
+001-02-23-42
+MCC+MNC in BCD: 00 f1 20 
+001-02-23-42
+RA test...passed
+Constructed RA:
+001-002-23-42 (3-digit MNC)
+MCC+MNC in BCD: 00 21 00 
+001-002-23-42 (3-digit MNC)
+RA test...passed
+Constructed RA:
+012-34-56-78
+MCC+MNC in BCD: 10 f2 43 
+012-34-56-78
+RA test...passed
+Constructed RA:
+012-034-23-42 (3-digit MNC)
+MCC+MNC in BCD: 10 42 30 
+012-034-23-42 (3-digit MNC)
+RA test...passed
+Constructed RA:
+123-456-23-42
+MCC+MNC in BCD: 21 63 54 
+123-456-23-42 (3-digit MNC)
+RA test...passed
+Constructed RA:
+123-456-23-42 (3-digit MNC)
+MCC+MNC in BCD: 21 63 54 
+123-456-23-42 (3-digit MNC)
 RA test...passed
 - gsm48_generate_lai() from 077-121-666-0
   Encoded 70 17 21 02 9a 
@@ -46,6 +81,14 @@
   Encoded 00 f0 00 00 00 
   gsm48_decode_lai2() gives  000-00-0-0
   passed
+- gsm48_generate_lai() from 000-000-0-0 (3-digit MNC)
+  Encoded 00 f0 00 00 00 
+  gsm48_decode_lai() gives  000-00-0-0
+  passed
+- gsm48_generate_lai2() from 000-000-0-0 (3-digit MNC)
+  Encoded 00 00 00 00 00 
+  gsm48_decode_lai2() gives  000-000-0-0 (3-digit MNC)
+  passed
 - gsm48_generate_lai() from 999-999-65535-0
   Encoded 99 99 99 ff ff 
   gsm48_decode_lai() gives  999-999-65535-0
@@ -54,3 +97,51 @@
   Encoded 99 99 99 ff ff 
   gsm48_decode_lai2() gives  999-999-65535-0 (3-digit MNC)
   passed
+- gsm48_generate_lai() from 001-02-23-0
+  Encoded 00 f1 20 00 17 
+  gsm48_decode_lai() gives  001-02-23-0
+  passed
+- gsm48_generate_lai2() from 001-02-23-0
+  Encoded 00 f1 20 00 17 
+  gsm48_decode_lai2() gives  001-02-23-0
+  passed
+- gsm48_generate_lai() from 001-002-23-0 (3-digit MNC)
+  Encoded 00 f1 20 00 17 
+  gsm48_decode_lai() gives  001-02-23-0
+  passed
+- gsm48_generate_lai2() from 001-002-23-0 (3-digit MNC)
+  Encoded 00 21 00 00 17 
+  gsm48_decode_lai2() gives  001-002-23-0 (3-digit MNC)
+  passed
+- gsm48_generate_lai() from 012-34-56-0
+  Encoded 10 f2 43 00 38 
+  gsm48_decode_lai() gives  012-34-56-0
+  passed
+- gsm48_generate_lai2() from 012-34-56-0
+  Encoded 10 f2 43 00 38 
+  gsm48_decode

[PATCH] libosmocore[master]: gsm: add gsm48_mnc_from_str() and gsm48_mnc_cmp(), for 3-dig...

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6663

gsm: add gsm48_mnc_from_str() and gsm48_mnc_cmp(), for 3-digit MNC

gsm48_mnc_from_str() preserves leading zeros in the string and is useful for
VTY config parsing.

gsm48_mnc_cmp() will be used by osmo-sgsn.git

Change-Id: Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6
---
M include/osmocom/gsm/gsm48.h
M src/gsm/gsm48.c
M src/gsm/libosmogsm.map
3 files changed, 63 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/63/6663/1

diff --git a/include/osmocom/gsm/gsm48.h b/include/osmocom/gsm/gsm48.h
index 9d312c2..37c421d 100644
--- a/include/osmocom/gsm/gsm48.h
+++ b/include/osmocom/gsm/gsm48.h
@@ -63,3 +63,7 @@
 void gsm48_mcc_mnc_to_bcd2(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc, bool 
mnc_3_digits);
 void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc);
 void gsm48_mcc_mnc_from_bcd2(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc, 
bool *mnc_3_digits);
+
+int gsm48_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits);
+
+int gsm48_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool 
b_mnc_3_digits);
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index 122f7ea..be2a976 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -530,6 +530,63 @@
}
 }
 
+/* Convert string to MNC, detecting 3-digit MNC with leading zeros.
+ * Return mnc_3_digits as false if the MNC's most significant digit is encoded 
as 0xF, true
+ * otherwise; i.e. true if MNC > 99 or if it is represented with leading zeros 
instead of 0xF.
+ * \param mnc_str[in]  String representation of an MNC, with or without 
leading zeros.
+ * \param mnc[out] MNC result buffer, or NULL.
+ * \param[out] mnc_3_digitsResult buffer for 3-digit flag, or NULL.
+ * \returns zero on success, -EINVAL in case of surplus characters, negative 
errno in case of conversion
+ *  errors.
+ */
+int gsm48_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits)
+{
+   uint16_t _mnc = 0;
+   bool _mnc_3_digits = false;
+   char *endptr;
+   int rc = 0;
+
+   if (!mnc_str || !isdigit(mnc_str[0])) {
+   /* return invalid, but give strtol a shot anyway, for callers 
that don't want to be
+* strict */
+   rc = -EINVAL;
+   }
+   errno = 0;
+   _mnc = strtol(mnc_str, &endptr, 10);
+   if (errno)
+   rc = -errno;
+   else if (*endptr)
+   rc = -EINVAL;
+   _mnc_3_digits = strlen(mnc_str) > 2;
+
+   if (mnc)
+   *mnc = _mnc;
+   if (mnc_3_digits)
+   *mnc_3_digits = _mnc_3_digits;
+   return rc;
+}
+
+/* Compare two MNC with three-digit flag.
+ * The mnc_3_digits flags passed in only have an effect if the MNC are < 100, 
i.e. if they would amount
+ * to a change in leading zeros in a BCD representation. An MNC >= 100 implies 
three digits, and the flag
+ * is actually ignored.
+ * \param a_mnc[in]"Left" side MNC.
+ * \param a_mnc_3_digits[in]   "Left" side three-digits flag.
+ * \param b_mnc[in]"Right" side MNC.
+ * \param b_mnc_3_digits[in]   "Right" side three-digits flag.
+ * \returns 0 if the MNC are equal, -1 if a < b or a shorter, 1 if a > b or a 
longer. */
+int gsm48_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool 
b_mnc_3_digits)
+{
+   if (a_mnc < b_mnc)
+   return -1;
+   if (a_mnc > b_mnc)
+   return 1;
+   /* a_mnc == b_mnc, but same amount of leading zeros? */
+   if (a_mnc < 100 && a_mnc_3_digits != b_mnc_3_digits)
+   return a_mnc_3_digits ? 1 : -1;
+   return 0;
+}
+
 /*! Encode TS 04.08 Location Area Identifier, legacy implementation.
  * Instead use gsm48_generate_lai2(), which is capable of three-digit MNC with 
leading zeros.
  *  \param[out] caller-provided memory for output
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 917eab2..9e3de75 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -272,6 +272,8 @@
 osmo_mcc_mnc_name;
 osmo_mcc_mnc_name2;
 osmo_rai_name;
+gsm48_mnc_from_str;
+gsm48_mnc_cmp;
 gsm48_chan_mode_names;
 gsm_chan_t_names;
 gsm48_pdisc_names;

-- 
To view, visit https://gerrit.osmocom.org/6663
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] libosmocore[master]: gsm0408_test: test new gsm48_{decode, generate}_lai2() functions

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6661

gsm0408_test: test new gsm48_{decode,generate}_lai2() functions

Change-Id: I4c8492b8055803d2857f1ef30aede088778b085b
---
M tests/gsm0408/gsm0408_test.c
M tests/gsm0408/gsm0408_test.ok
2 files changed, 45 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/61/6661/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index 9e552ab..c40c643 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -187,6 +187,34 @@
printf("  FAIL\n");
 }
 
+static inline void check_lai2(const struct gprs_ra_id *raid)
+{
+   int rc;
+   struct gsm48_loc_area_id lai = {};
+   struct gprs_ra_id decoded = {};
+   struct gprs_ra_id _laid = *raid;
+   struct gprs_ra_id *laid = &_laid;
+   laid->rac = 0;
+
+   printf("- gsm48_generate_lai2() from "); dump_ra(laid);
+
+   gsm48_generate_lai2(&lai, laid->mcc, laid->mnc, laid->mnc_3_digits, 
laid->lac);
+   printf("  Encoded %s\n", osmo_hexdump((unsigned char*)&lai, 
sizeof(lai)));
+   rc = gsm48_decode_lai2(&lai, &decoded.mcc, &decoded.mnc, 
&decoded.mnc_3_digits, &decoded.lac);
+   if (rc) {
+   printf("  gsm48_decode_lai2() returned %d --> FAIL\n", rc);
+   return;
+   }
+   printf("  gsm48_decode_lai2() gives  "); dump_ra(&decoded);
+   if (decoded.mcc == laid->mcc
+   && decoded.mnc == laid->mnc
+   && decoded.lac == laid->lac
+   && decoded.mnc_3_digits == (laid->mnc_3_digits || laid->mnc > 99))
+   printf("  passed\n");
+   else
+   printf("  FAIL\n");
+}
+
 static struct gprs_ra_id test_ra_cap_items[] = {
{
.mcc = 77,
@@ -228,6 +256,7 @@
 
for (i = 0; i < ARRAY_SIZE(test_ra_cap_items); i++) {
check_lai(&test_ra_cap_items[i]);
+   check_lai2(&test_ra_cap_items[i]);
}
 }
 
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index cc56763..be2a1de 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -26,15 +26,31 @@
   Encoded 70 17 21 02 9a 
   gsm48_decode_lai() gives  077-121-666-0
   passed
+- gsm48_generate_lai2() from 077-121-666-0
+  Encoded 70 17 21 02 9a 
+  gsm48_decode_lai2() gives  077-121-666-0 (3-digit MNC)
+  passed
 - gsm48_generate_lai() from 084-98-11-0
   Encoded 80 f4 89 00 0b 
   gsm48_decode_lai() gives  084-98-11-0
+  passed
+- gsm48_generate_lai2() from 084-98-11-0
+  Encoded 80 f4 89 00 0b 
+  gsm48_decode_lai2() gives  084-98-11-0
   passed
 - gsm48_generate_lai() from 000-00-0-0
   Encoded 00 f0 00 00 00 
   gsm48_decode_lai() gives  000-00-0-0
   passed
+- gsm48_generate_lai2() from 000-00-0-0
+  Encoded 00 f0 00 00 00 
+  gsm48_decode_lai2() gives  000-00-0-0
+  passed
 - gsm48_generate_lai() from 999-999-65535-0
   Encoded 99 99 99 ff ff 
   gsm48_decode_lai() gives  999-999-65535-0
   passed
+- gsm48_generate_lai2() from 999-999-65535-0
+  Encoded 99 99 99 ff ff 
+  gsm48_decode_lai2() gives  999-999-65535-0 (3-digit MNC)
+  passed

-- 
To view, visit https://gerrit.osmocom.org/6661
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4c8492b8055803d2857f1ef30aede088778b085b
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] libosmocore[master]: gsm0408_test: also test gsm48_generate_lai() and gsm48_decod...

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6658

gsm0408_test: also test gsm48_generate_lai() and gsm48_decode_lai()

Change-Id: Idd6cee090464bc92b654332904a9a08edf16e5c9
---
M tests/gsm0408/gsm0408_test.c
M tests/gsm0408/gsm0408_test.ok
2 files changed, 53 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/58/6658/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index ad45507..a0e740a 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -159,6 +159,33 @@
printf("passed\n");
 }
 
+static inline void check_lai(const struct gprs_ra_id *raid)
+{
+   int rc;
+   struct gsm48_loc_area_id lai = {};
+   struct gprs_ra_id decoded = {};
+   struct gprs_ra_id _laid = *raid;
+   struct gprs_ra_id *laid = &_laid;
+   laid->rac = 0;
+
+   printf("- gsm48_generate_lai() from "); dump_ra(laid);
+
+   gsm48_generate_lai(&lai, laid->mcc, laid->mnc, laid->lac);
+   printf("  Encoded %s\n", osmo_hexdump((unsigned char*)&lai, 
sizeof(lai)));
+   rc = gsm48_decode_lai(&lai, &decoded.mcc, &decoded.mnc, &decoded.lac);
+   if (rc) {
+   printf("  gsm48_decode_lai() returned %d --> FAIL\n", rc);
+   return;
+   }
+   printf("  gsm48_decode_lai() gives  "); dump_ra(&decoded);
+   if (decoded.mcc == laid->mcc
+   && decoded.mnc == laid->mnc
+   && decoded.lac == laid->lac)
+   printf("  passed\n");
+   else
+   printf("  FAIL\n");
+}
+
 static struct gprs_ra_id test_ra_cap_items[] = {
{
.mcc = 77,
@@ -192,6 +219,15 @@
 
for (i = 0; i < ARRAY_SIZE(test_ra_cap_items); i++)
check_ra(&test_ra_cap_items[i]);
+}
+
+static void test_lai_encode_decode(void)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(test_ra_cap_items); i++) {
+   check_lai(&test_ra_cap_items[i]);
+   }
 }
 
 static void test_mid_from_tmsi(void)
@@ -229,6 +265,7 @@
test_mid_from_tmsi();
test_mid_from_imsi();
test_ra_cap();
+   test_lai_encode_decode();
 
return EXIT_SUCCESS;
 }
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index dc19eea..7612c12 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -22,3 +22,19 @@
 MCC+MNC in BCD: 99 99 99 
 999-999-65535-255
 RA test...passed
+- gsm48_generate_lai() from 077-121-666-0
+  Encoded 70 17 21 02 9a 
+  gsm48_decode_lai() gives  077-121-666-0
+  passed
+- gsm48_generate_lai() from 084-98-11-0
+  Encoded 80 f4 89 00 0b 
+  gsm48_decode_lai() gives  084-98-11-0
+  passed
+- gsm48_generate_lai() from 000-00-0-0
+  Encoded 00 f0 00 00 00 
+  gsm48_decode_lai() gives  000-00-0-0
+  passed
+- gsm48_generate_lai() from 999-999-65535-0
+  Encoded 99 99 99 ff ff 
+  gsm48_decode_lai() gives  999-999-65535-0
+  passed

-- 
To view, visit https://gerrit.osmocom.org/6658
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd6cee090464bc92b654332904a9a08edf16e5c9
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] libosmocore[master]: gsm0408_test: RA test: include min/max value cases

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6657

gsm0408_test: RA test: include min/max value cases

(Preparation for adding 3-digit MNC)

Change-Id: Ifbc167de0cc039858112677b8d0cd14a2c8af086
---
M tests/gsm0408/gsm0408_test.c
M tests/gsm0408/gsm0408_test.ok
2 files changed, 22 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/57/6657/1

diff --git a/tests/gsm0408/gsm0408_test.c b/tests/gsm0408/gsm0408_test.c
index aa6a8be..ad45507 100644
--- a/tests/gsm0408/gsm0408_test.c
+++ b/tests/gsm0408/gsm0408_test.c
@@ -172,6 +172,18 @@
.lac = 11,
.rac = 89,
},
+   {
+   .mcc = 0,
+   .mnc = 0,
+   .lac = 0,
+   .rac = 0,
+   },
+   {
+   .mcc = 999,
+   .mnc = 999,
+   .lac = 65535,
+   .rac = 255,
+   },
 };
 
 static void test_ra_cap(void)
diff --git a/tests/gsm0408/gsm0408_test.ok b/tests/gsm0408/gsm0408_test.ok
index a3d801d..dc19eea 100644
--- a/tests/gsm0408/gsm0408_test.ok
+++ b/tests/gsm0408/gsm0408_test.ok
@@ -12,3 +12,13 @@
 MCC+MNC in BCD: 80 f4 89 
 084-98-11-89
 RA test...passed
+Constructed RA:
+000-00-0-0
+MCC+MNC in BCD: 00 f0 00 
+000-00-0-0
+RA test...passed
+Constructed RA:
+999-999-65535-255
+MCC+MNC in BCD: 99 99 99 
+999-999-65535-255
+RA test...passed

-- 
To view, visit https://gerrit.osmocom.org/6657
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifbc167de0cc039858112677b8d0cd14a2c8af086
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


[PATCH] osmo-pcu[master]: implement support for 3-digit MNC with leading zeros

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/

implement support for 3-digit MNC with leading zeros

Receive the mnc_3_digits flag from the PCU interface. Bump the PCU interface
version from 7 to 9 to match osmo-bts (see
I49cd762c3c9d7ee6a82451bdf3ffa2a060767947 there).

Add 3-digit flags and use the new RAI and LAI API from libosmocore throughout
the code base to be able to handle an MNC < 100 that has three digits (leading
zeros).

Depends: Id2240f7f518494c9df6c8bda52c0d5092f90f221 (libosmocore),
 Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6 (libosmocore),
 I49cd762c3c9d7ee6a82451bdf3ffa2a060767947 (osmo-bts)

Change-Id: I787fed84a7b613158a5618dd5cffafe4e4927234
---
M include/osmocom/pcu/pcuif_proto.h
M src/gprs_bssgp_pcu.cpp
M src/gprs_bssgp_pcu.h
M src/pcu_l1_if.cpp
M src/pcu_main.cpp
M tests/alloc/AllocTest.cpp
M tests/alloc/MslotTest.cpp
M tests/edge/EdgeTest.cpp
M tests/emu/pcu_emu.cpp
M tests/fn/FnTest.cpp
M tests/llc/LlcTest.cpp
M tests/ms/MsTest.cpp
M tests/tbf/TbfTest.cpp
M tests/types/TypesTest.cpp
14 files changed, 40 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/66//1

diff --git a/include/osmocom/pcu/pcuif_proto.h 
b/include/osmocom/pcu/pcuif_proto.h
index 39103ee..2b4b15c 100644
--- a/include/osmocom/pcu/pcuif_proto.h
+++ b/include/osmocom/pcu/pcuif_proto.h
@@ -5,7 +5,7 @@
 
 #define PCU_SOCK_DEFAULT   "/tmp/pcu_bts"
 
-#define PCU_IF_VERSION 0x07
+#define PCU_IF_VERSION 0x09
 #define TXT_MAX_LEN128
 
 /* msg_type */
@@ -105,7 +105,9 @@
struct gsm_pcu_if_info_trx trx[8];  /* TRX infos per BTS */
uint8_t bsic;
/* RAI */
-   uint16_tmcc, mnc, lac, rac;
+   uint16_tmcc, mnc;
+   uint8_t mnc_3_digits;
+   uint16_tlac, rac;
/* NSE */
uint16_tnsei;
uint8_t nse_timer[7];
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp
index 3cc86e2..6727735 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.cpp
@@ -44,6 +44,7 @@
 
 extern void *tall_pcu_ctx;
 extern uint16_t spoof_mcc, spoof_mnc;
+extern bool spoof_mnc_3_digits;
 
 static void bvc_timeout(void *_priv);
 
@@ -876,15 +877,11 @@
 struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts 
*bts,
uint16_t local_port, uint32_t sgsn_ip,
uint16_t sgsn_port, uint16_t nsei, uint16_t nsvci, uint16_t bvci,
-   uint16_t mcc, uint16_t mnc, uint16_t lac, uint16_t rac,
+   uint16_t mcc, uint16_t mnc, bool mnc_3_digits, uint16_t lac, uint16_t 
rac,
uint16_t cell_id)
 {
struct sockaddr_in dest;
int rc;
-
-   mcc = ((mcc & 0xf00) >> 8) * 100 + ((mcc & 0x0f0) >> 4) * 10 + (mcc & 
0x00f);
-   mnc = ((mnc & 0xf00) >> 8) * 100 + ((mnc & 0x0f0) >> 4) * 10 + (mnc & 
0x00f);
-   cell_id = ntohs(cell_id);
 
/* if already created... return the current address */
if (the_pcu.bctx)
@@ -930,7 +927,13 @@
return NULL;
}
the_pcu.bctx->ra_id.mcc = spoof_mcc ? : mcc;
-   the_pcu.bctx->ra_id.mnc = spoof_mnc ? : mnc;
+   if (spoof_mnc) {
+   the_pcu.bctx->ra_id.mnc = spoof_mnc;
+   the_pcu.bctx->ra_id.mnc_3_digits = spoof_mnc_3_digits;
+   } else {
+   the_pcu.bctx->ra_id.mnc = mnc;
+   the_pcu.bctx->ra_id.mnc_3_digits = mnc_3_digits;
+   }
the_pcu.bctx->ra_id.lac = lac;
the_pcu.bctx->ra_id.rac = rac;
the_pcu.bctx->cell_id = cell_id;
diff --git a/src/gprs_bssgp_pcu.h b/src/gprs_bssgp_pcu.h
index 4eda57d..4127244 100644
--- a/src/gprs_bssgp_pcu.h
+++ b/src/gprs_bssgp_pcu.h
@@ -77,7 +77,7 @@
 struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts 
*bts,
uint16_t local_port,
uint32_t sgsn_ip, uint16_t sgsn_port, uint16_t nsei,
-   uint16_t nsvci, uint16_t bvci, uint16_t mcc, uint16_t mnc,
+   uint16_t nsvci, uint16_t bvci, uint16_t mcc, uint16_t mnc, bool 
mnc_3_digits,
uint16_t lac, uint16_t rac, uint16_t cell_id);
 
 void gprs_bssgp_destroy(void);
diff --git a/src/pcu_l1_if.cpp b/src/pcu_l1_if.cpp
index 664a7b7..85dbfb9 100644
--- a/src/pcu_l1_if.cpp
+++ b/src/pcu_l1_if.cpp
@@ -408,6 +408,7 @@
int rc = 0;
unsigned int trx, ts;
int i;
+   uint16_t cell_id = ntohs(info_ind->cell_id);
 
if (info_ind->version != PCU_IF_VERSION) {
fprintf(stderr, "PCU interface version number of BTS (%d) is "
@@ -434,11 +435,11 @@
exit(0);
}
LOGP(DL1IF, LOGL_INFO, "BTS available\n");
-   LOGP(DL1IF, LOGL_DEBUG, " mcc=%x\n", info_ind->mcc);
-   LOGP(DL1IF, LOGL_DEBUG, " mnc=%x\n", info_ind->mnc);
+   LOGP(DL1IF, LOGL_DEBUG, " mcc=%03u\n", info_ind->mcc);
+   LOGP(DL1IF, LOGL_DEBUG, " mnc=%0*u\n", info_ind->mnc_3_digits, 
info_ind->mnc);
LOGP(DL1IF, LOGL_DEBUG, " lac=%d\

[PATCH] libosmocore[master]: GSM_MNC_INVALID

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6664

GSM_MNC_INVALID

Change-Id: Ieee7add0bd6d94cf84743a49794bbcd38561b72f
---
M include/osmocom/gsm/gsm48.h
1 file changed, 4 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/64/6664/1

diff --git a/include/osmocom/gsm/gsm48.h b/include/osmocom/gsm/gsm48.h
index 37c421d..7c32cfb 100644
--- a/include/osmocom/gsm/gsm48.h
+++ b/include/osmocom/gsm/gsm48.h
@@ -11,6 +11,10 @@
 /* reserved according to GSM 03.03 ยง 2.4 */
 #define GSM_RESERVED_TMSI   0x
 
+/* Valid MCC and MNC range from 0 to 999.
+ * To mark an invalid / unset MNC, this value shall be used. */
+#define GSM_MCC_MNC_INVALID 0x
+
 /* A parsed GPRS routing area */
 struct gprs_ra_id {
uint16_tmcc;

-- 
To view, visit https://gerrit.osmocom.org/6664
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieee7add0bd6d94cf84743a49794bbcd38561b72f
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 


  1   2   >