Compare commits

...

261 Commits

Author SHA1 Message Date
Holger Hans Peter Freyther
161bd6d253 Increase version number 2010-04-06 17:56:01 +02:00
Holger Hans Peter Freyther
add3472e9f bsc_msc_ip.c: Do not attempt to disconnect when not connected
This is fixing a segfault due calling bsc_unregsiter_fd twice
without being in the list.
2010-04-06 17:55:33 +02:00
Holger Hans Peter Freyther
33b0bee457 bsc_msc_ip.c: Crash fix when the MSC disconnects
Check if we do have the msc_data before invoking code in
bssap.c. We might have lost the MSC connection and asked
for the channel to be taken down but we might have received
one last message from the BTS.
2010-04-06 17:44:39 +02:00
Holger Hans Peter Freyther
6949db1bd8 nat: Send a RLSD to the network for connections belonging to the BSC
Sending a RLSD with SCCP failure makes the MSC free all the resources
(MGCP, audio channels), right now we are ignoring the RLC we get from
the network and print a unhandled message.
2010-04-06 17:44:39 +02:00
Holger Hans Peter Freyther
8ae0080e21 bsc_msc_ip.c: Register the SIGUSR2 handler... to really handle it. 2010-04-06 17:44:39 +02:00
Holger Hans Peter Freyther
546c296c4a nat: Print a MSG when receiving unknown SCCP messages. 2010-04-06 17:44:39 +02:00
Holger Hans Peter Freyther
86f42eb6a5 nat: Store the config in the connection instead of the lac
This allows that we can print the Nr. next to the lac
and it allows us to change the lac at runtime without
reconnecting the BSC.
2010-04-06 15:12:25 +02:00
Holger Hans Peter Freyther
494c086dca nat: Close the filedescriptor when ignoring the request. 2010-04-06 12:42:35 +02:00
Holger Hans Peter Freyther
6b18c8f3b6 bsc_msc_ip.c: Remove unused variable. 2010-04-06 12:25:19 +02:00
Holger Hans Peter Freyther
87f6d26c2e [vty] Add the nat area to the list of categories. 2010-04-06 12:09:02 +02:00
Holger Hans Peter Freyther
fab2ff34c4 nat: Add logging commands for the nat as well. 2010-04-06 12:03:11 +02:00
Holger Hans Peter Freyther
06d353e02e [mgcp] Add the logging commands for the MGCP command. 2010-04-06 12:03:05 +02:00
Holger Hans Peter Freyther
dfe47549c6 [vty] Move the VTY logging commands to a new file
Currently vty_interface.c is used for the BSC config, in case of
the MGCP Gateway or the BSC Nat process these logging commands are
not available. Move the commands to a new vty_interface_cmds.c file
to allow to share basic commands across different programs.
2010-04-06 11:55:37 +02:00
Holger Hans Peter Freyther
c70e8c2103 nat: Fix thinko... use the right fd to determine the IP of the bts
Use the fd of the BSC Connection to determine the IP address of the
BTS as we are seeing it.
2010-04-06 11:17:56 +02:00
Holger Hans Peter Freyther
b462a03c35 nat: Improve the log message and print the errno/strerror(errno) 2010-04-06 11:17:07 +02:00
Holger Hans Peter Freyther
6e0ec5b6fa [mgcp] Do not patch RTP payload when type is set to -1.
For the nat we might or might not want to patch it, do not
patch if we have no valid rtp payload type.
2010-04-06 11:15:50 +02:00
Holger Hans Peter Freyther
6768387f16 nat: Set the MGCP audio payload to -1.
This value is copied into the bts_audio_payload when allocating
a BTS MGCP endpoint. For the nat we have actually no interest in
patching MGCP messages. We will patch them to the network because
the code will do it anyway, we will not patch things back to the
BTS.
2010-04-06 11:14:03 +02:00
Holger Hans Peter Freyther
5ef1234dd3 [mgcp] Reset the the address when freeing the endp as well 2010-04-06 11:12:22 +02:00
Holger Hans Peter Freyther
581e58d166 Revert "nat: Remember where the BTS is listening for things."
Remove the code to parse port as we need to discover the
BTS behind the nat and most likely it will have a different
port than the one advertised by the BTS.

This reverts commit c6a1fe773d.
2010-04-06 11:06:11 +02:00
Holger Hans Peter Freyther
e308bb466a nat: Print the unknown byte as a integer instead of charachter
The value might be a non printable one.
2010-04-06 10:25:40 +02:00
Holger Hans Peter Freyther
e4be5394ef bsc_msc.c: Print the error message of the connection. 2010-04-06 10:25:00 +02:00
Holger Hans Peter Freyther
81e1edd3e6 nat: Patch IT messages as well..
We need to patch the source/dest reference inside the messages
as well otherwise we will see failures in the SCCP connection
on long calls.
2010-04-06 10:22:34 +02:00
Holger Hans Peter Freyther
cfd1c28604 nat: Test forwarding Inactivity Test messages.
No change needed to the code.
2010-04-06 10:22:01 +02:00
Holger Hans Peter Freyther
3ba8963a1d nat: Close all endpoints used by a BSC when the BSC is gone
Cleanup all endpoints that belonged to a given BSC. This is
one part of the cleanup, the other is to bring down the SCCP
link properly.
2010-04-05 23:09:27 +02:00
Holger Hans Peter Freyther
238d156481 nat: Remember a pending delete on an endpoint and carry it out later 2010-04-05 22:56:49 +02:00
Holger Hans Peter Freyther
516c4f073a [mgcp] Fix navigation in the vty hierachy (make exit work)
Make exit from the MGCP node work properly.
2010-04-05 22:42:18 +02:00
Holger Hans Peter Freyther
fa22aa6bbd nat: Fix navigation inside the config structure (fix exit)
Make sure exit in nat and nat/bsc is working and we go one
level up.
2010-04-05 22:40:49 +02:00
Holger Hans Peter Freyther
4072ceed32 nat: remove is called on already patched connections..
Fix the test to search for the original message instead
of the already patched one that should not find any items
anyway.

The remove is called on already patched connections so we
need to match it with the patch reference count.
2010-04-05 21:44:51 +02:00
Holger Hans Peter Freyther
cf6bf63a0d bsc_msc_ip: Use the force_free method to free the SCCP connection
Before the connection was not properly removed from the list of
connections and our connection list contained a dangling pointer.
2010-04-05 18:15:19 +02:00
Holger Hans Peter Freyther
88b614110f [sccp] Add a force_free method for connections
E.g. when the underlying connection transport medium is gone
one needs to force to close SCCP connections, add this helper.

It will remove the connection from the list of connections and
it will free the data.
2010-04-05 18:15:12 +02:00
Holger Hans Peter Freyther
d9b825a5f5 nat: Print the SCCP ref's as hex numbers
This allows to more easily compare the numbers with traces
seen in wireshark.
2010-04-05 18:03:39 +02:00
Holger Hans Peter Freyther
b91e5f1da4 nat: Avoid crashing when we have no pending transaction 2010-04-05 18:00:05 +02:00
Holger Hans Peter Freyther
07bb509434 nat: Logging improvement for the nat.
Print some more information, e.g. when a BSC is connected
and authenticated, print the SCCP ref number.
2010-04-05 17:58:52 +02:00
Holger Hans Peter Freyther
08db6ca509 [mgcp] Reduce this to a debug message...
This message can get in the way during a re-establishment
of the MSC connection while the MSCs gateway is still sending
data to us.
2010-04-05 17:57:10 +02:00
Holger Hans Peter Freyther
6446ded81c bsc_msc_ip: Verify that the sccp connection is present.
The SCCP might have been freed by the error case already
so we need to check this one for zero.
2010-04-05 17:16:30 +02:00
Holger Hans Peter Freyther
7b8f6064d6 nat: Print the MSC multiplex as well 2010-04-05 10:10:33 +02:00
Holger Hans Peter Freyther
c6a1fe773d nat: Remember where the BTS is listening for things.
Extract the port from the BSS's MGCP Gateway so we know
where to forward the data to.
2010-04-05 09:10:30 +02:00
Holger Hans Peter Freyther
729d468fdf nat: No need to match \r\n when parsing the C: N 2010-04-05 09:07:39 +02:00
Holger Hans Peter Freyther
b37ce4c5a4 [mgcp] Use a different port to more easily differentiate 2010-04-05 09:01:28 +02:00
Holger Hans Peter Freyther
5cd62c0ba5 [mgcp] Print the BTS IP addr of the endpoint. 2010-04-05 09:00:53 +02:00
Holger Hans Peter Freyther
1e1acafafd nat: Remove the broken empty line check, follow \n vs \r\n of input
Instead of checking the token for NULL we need to check if running
was set to null. Look at the data of the token and check if the line
was ending with a \r\n or \n and then when rewriting a line use that
line ending as well. Add a new test for that.
2010-04-04 19:40:25 +02:00
Holger Hans Peter Freyther
fb83b7a86d [mgcp] Start to look into the MGCP messages and extract the CI
we will need the call identifier for the MDCX and DLCX message
for now we were just assuming it would increment, use som python
to extract the CI from a possible response, also switch back to
a blocking read to test the BSC nat.
2010-04-04 18:39:56 +02:00
Holger Hans Peter Freyther
ef0b641f63 [ipa] When including MGCP our messages might be bigger than 300 byte
The length field of the IPA header allows to have 16bit numbers
and I just ran into the 300 byte limit with MGCP messages. Make it
three times the size and see how long this is going to be enough.
2010-04-04 18:12:37 +02:00
Holger Hans Peter Freyther
27e0bfd3c7 nat: Use a ptr that was allocated by talloc
The endp is part of an array allocated by talloc and simple
array members do not qualify as a context start address.
2010-04-04 18:11:49 +02:00
Holger Hans Peter Freyther
bbfff6ec39 nat: Make rewrite work on string, read to a string first, copy to msgb
The MGCP protocol parsing is adding '\0' to make sure we do not
parse beyond where we should parse. This does not mix with strtok
or similiar routines.
For now we will read the msg into a global array first, then copy
it to the msgb for mgcp protocol handling and if we are required
to forward it to the MGCP we have a untouched copy we will modify
into our own msgb.
2010-04-04 18:09:10 +02:00
Holger Hans Peter Freyther
dc0914df09 [mgcp] Set the right variable to NULL otherwise we get a double free 2010-04-04 17:58:26 +02:00
Holger Hans Peter Freyther
0db691dcf6 [mgcp] Fix the transaction id of the AUEP request 2010-04-04 16:37:21 +02:00
Holger Hans Peter Freyther
bb45b73b20 bsc_msc_ip.c: Fix crash for the hexdump during writing..
we need to set the msgb l2h to the right position otherwise
when trying to dump it we will have a nice crash.
2010-04-04 16:30:39 +02:00
Holger Hans Peter Freyther
5f5c1b6bcb bsc_msc_ip.c: Fix the reading of data...
len contains the actual length of the message and data_len
contains the size of the message. We want to read up to
data_len and not up to 0 bytes.
2010-04-04 16:29:44 +02:00
Holger Hans Peter Freyther
e51cf4f946 bsc_msc_ip.c: Use another kernel feature to bind to a random port 2010-04-04 15:53:38 +02:00
Holger Hans Peter Freyther
749ba7f5ad bsc_msc_ip.c: Use strerror to print the errno variable. 2010-04-04 15:44:53 +02:00
Holger Hans Peter Freyther
860c8955c3 Revert "bsc_msc_ip: Use the autobind functionality of the kernel"
The autobind is not working as I wanted it to work. So we will
revert this for now and then try something else.

This reverts commit fd876b7488.
2010-04-04 15:24:11 +02:00
Holger Hans Peter Freyther
c33701c4e5 nat: Check the authentication bit later...
When moving it up here the code started to reject
the identity responses of the bsc and we would
never authenticate. Move it back down.
2010-04-02 03:47:09 +02:00
Holger Hans Peter Freyther
44d92b4728 bsc_msc_ip.c: Return after having freed the msgb
When reading MGCP is failing (e.g. because the udp socket
is not connected yet) we would have freed the msgb but we
didn't return and then executed msgb_put on a dead buffer.
2010-04-02 03:28:30 +02:00
Holger Hans Peter Freyther
8aaec620da nat: Return MGCP messages to the call agent
Attempt to find the message by transaction id, then patch
the response and use the IP/PORT of the local network, update
the ci with the one from the BSC.

This is currently not tracking any state of the MGCP and will
not handle two bsc's... this will need to happen later.

With this in we should be feature complete and now enter the
mode of making all of this work reliable and fixing thinko's
and other bugs.
2010-04-01 10:16:28 +02:00
Holger Hans Peter Freyther
a5a4014d67 nat: Allow to send MGCP messages from the BSC to the network 2010-04-01 08:47:12 +02:00
Holger Hans Peter Freyther
9d519189ae nat: Handle CRCX/MDCX/DLCX at the nat
* Forward a rewritten msg to the BSS. We change the IP and port
  to point to the NAT instead of the core network. We also keep
  track of the BSC and the transacition id.
* Handle the case where we have not found a SCCP connection and
  need to send a response ourselves.
2010-04-01 08:21:33 +02:00
Holger Hans Peter Freyther
f0fc618782 [mgcp] Look at the bts addr set at the endpoint
This will allow to discover the ports of a bts when we only know
the addr and have multiple bts's to handle.
2010-04-01 07:56:04 +02:00
Holger Hans Peter Freyther
c57575bea8 nat: Test rewriting of MGCP messages to patch ip and port
Add code to change the ip and port for audio data inside
MGCP messages. This is needed because the BSS might be
behind the NAT and can not reach the network directly and
might be behind a nat so the announced sourceport is not
the one as we see it.
2010-04-01 07:41:23 +02:00
Holger Hans Peter Freyther
8cdfe9fc37 nat: Add code to find a BSC connection by the given msc multiplex 2010-04-01 07:41:23 +02:00
Holger Hans Peter Freyther
0959f8cbe6 [mgcp] Export header parsing via mgcp internal
This will be used by the NAT code to implement custom protocol
handling on top of that.
2010-04-01 07:41:23 +02:00
Holger Hans Peter Freyther
f21028985e [mgcp] Do not operate on the ->data pointer, use ->l2h instead
This would have been broken once we attempt to parse encapsulated
MGCP messages.
2010-03-31 13:26:46 +02:00
Holger Hans Peter Freyther
483b768ab2 bsc-msc: Flush the write queue when we have lost the connection 2010-03-31 13:15:26 +02:00
Holger Hans Peter Freyther
82cb311c4f nat: First go at handling MGCP inside the nat
Listen on the MGCP gateway port and let our protocol stack
handle everything for now. We will need to have some more
control over things though.
2010-03-31 13:15:19 +02:00
Holger Hans Peter Freyther
2980442e33 [mgcp] Degrade verbosity to debug 2010-03-31 12:31:09 +02:00
Holger Hans Peter Freyther
fa7afb31e9 nat: Add an example configuration for the BSC NAT with MGCP 2010-03-31 11:53:36 +02:00
Holger Hans Peter Freyther
7513b3a1c2 [mgcp] Add a new config option to set the call agent ip addr
In the case of the nat we only want to communicate with one
upstream call agent and this can now be configured.
2010-03-31 11:46:41 +02:00
Holger Hans Peter Freyther
135d99b36e [mgcp] Regroup struct mgcp_cfg members and provide some hints 2010-03-31 11:35:20 +02:00
Holger Hans Peter Freyther
5aaf7c164c [mgcp] Add a helper function to convert from GSM0808 ts/mux to MGCP endpoint
Move the conversion of GSM0808 timeslot and multiplex from
the bssap.c into the mgcp.h so it can be reused by multiple
users. The weird math comes from the mapping of the MSC...
2010-03-31 09:27:04 +02:00
Holger Hans Peter Freyther
790db1e01b nat: In the case of losing the MSC, reset all endpoints
When losing the SCCP connection make sure that we free all
endpoints. The disconnection of the BSC should already make
sure they are closed but this makes sure everything is
properly reset.
2010-03-31 09:16:56 +02:00
Holger Hans Peter Freyther
81a8975662 nat: bsc_mgcp_clear is called from within the remove function
No need to call it twice... All endpoints should be properly
freed as part of the SCCP disconnection.
2010-03-31 09:15:05 +02:00
Holger Hans Peter Freyther
fd876b7488 bsc_msc_ip: Use the autobind functionality of the kernel
We do not care about the source port for the callagent relay
and can use the autobind functionality of the kernel to pick
a port for us...
2010-03-31 08:41:52 +02:00
Holger Hans Peter Freyther
2ffe7aa340 bsc_msc_ip: Create a local UDP socket and relay MGCP messages
Attempt to bind to the local callagent port and send messages
from the MSC TCP connection to the MGCP and do it the otherway
around as well.
2010-03-31 08:39:53 +02:00
Holger Hans Peter Freyther
538ea6d5c6 [nat] Send a RSIP down to the BSC after it connects
Make sure the MGCP attached to the BSC is resetting all
endpoints whenever the BSC is connecting to us as we assume
that all endpoints are available.
2010-03-31 07:30:58 +02:00
Holger Hans Peter Freyther
e14ec0dab4 [mgcp] Handle the RSIP with resetting all endpoints
We could change that the message came from a special ip
address/port to secure this service in general but we don't
do that right now.
2010-03-31 07:01:35 +02:00
Holger Hans Peter Freyther
8252b9b947 [mgcp] Add some parsing for RSIP messages coming in
This will just call a callback and leave all the handling
to the application.
2010-03-31 06:39:35 +02:00
Holger Hans Peter Freyther
9fb88021dd [mgcp] Remove unused method from the mgcp
This was removed when sending the RSIP was
removed from the code.
2010-03-31 06:26:44 +02:00
Holger Hans Peter Freyther
b031d6ecae [mgcp] Switch from DEBUG to LOGP in the mgcp_main.c 2010-03-31 06:16:45 +02:00
Holger Hans Peter Freyther
fcfdde5390 [mgcp] Remove the sending of RSIP
This message is ignored by the call agent and we were
sending this on the first request which we maybe should
not ignore...
2010-03-30 15:41:03 +02:00
Holger Hans Peter Freyther
571ba8e4da nat: Add MGCP code and parsing to the nat code..
For the nat we will have NAT and MGCP in the same process
and this commit starts with that. We are linking in the MGCP
code and one can embed MGCP config snippets...
2010-03-30 13:08:32 +02:00
Holger Hans Peter Freyther
bed6234e26 [mgcp] The networking code needs a source addrs..
Make the source address mandantory and complain about
complain when it is missing. The address is mandantory
as it needs to be put into the MGCP messages...
2010-03-30 13:00:40 +02:00
Holger Hans Peter Freyther
9d24578812 [mgcp] Move mgcp init into the main method... 2010-03-30 12:43:53 +02:00
Holger Hans Peter Freyther
a087c4e75d [mgcp] Fix format string usage 2010-03-30 12:43:33 +02:00
Holger Hans Peter Freyther
6b64b26d8b nat: Look at the assignment command and remember on which timeslot the data is
This information will be needed when we are trying to forward
MGCP connections to and from the BSC through the IPA protocol.
2010-03-30 12:01:24 +02:00
Holger Hans Peter Freyther
22252a98e3 sccp: Move the destruction of the sccp connection to a new place 2010-03-30 10:45:48 +02:00
Holger Hans Peter Freyther
957bc93244 nat: Return the SCCP connection, change order of patching and updating
* Return the SCCP connection. This will be needed to store the
  assigned timeslot in there.
* Update code to work with this change
* This uncovered a bug in the CC handling, at the time the BSC was
  passed it was still a null pointer and the code would have failed.
2010-03-30 09:17:53 +02:00
Holger Hans Peter Freyther
18bbe2e8a0 misc: Do not prepend 0x when using %p in printf. 2010-03-30 08:41:17 +02:00
Holger Hans Peter Freyther
1b17913cbc nat: Fail more early in the case of not being authenticated
This is also fixing a possible memory leak.
2010-03-30 07:45:52 +02:00
Holger Hans Peter Freyther
ce2a36840d nat: Add test case and data for paging by lac test. 2010-03-30 06:51:53 +02:00
Holger Hans Peter Freyther
0e09feccb0 nat: Some more input validation... on the paging command. 2010-03-30 06:51:23 +02:00
Holger Hans Peter Freyther
40a1de699a nat: Documentation fix... use nat for the parameter 2010-03-30 06:39:37 +02:00
Holger Hans Peter Freyther
d906a366c8 nat: Verify that the configured LACs are unique across the nat 2010-03-30 06:08:56 +02:00
Holger Hans Peter Freyther
d44d4c8c8b nat: Move paging by lac handling code into the utils file
Moving it here means we can more easily test this code, there is one
behaviour change with the code that we only support paging messages
with one LAC and will silently ignore the others.
2010-03-30 05:57:42 +02:00
Holger Hans Peter Freyther
af0e1d7a85 nat: Add a test case for the connection tracking
This test case tests connectiont tracking by sending
a CR, getting a CC, sending a DTAP, receiving a DTAP,
receiving a RLSD, sending a RLC. It verifies that the
messages are properly patched specially the references
at the BSC.
2010-03-30 02:43:11 +02:00
Holger Hans Peter Freyther
d21b4d7f98 nat: Fix the lookup of connections to and from the BSC
When sending a message to the MSC in the case of DT1
messages we only have the address of the MSC, so we
need to go with that, otherwise (e.g. in case of a CR, RLC)
we do have the source address and need to patch it.

When forwarding a message to the BSC we do receive
a msg that should contain the patched address, we need
to unpatch it...
2010-03-29 17:43:32 +02:00
Holger Hans Peter Freyther
3bdaa69fb2 nat: Keep track of both sides of the connection
On a CC message we will need to remeber where the source local
reference of the network belonged so we can properly identify
the connection when receiving UDT messages.
2010-03-29 17:43:32 +02:00
Holger Hans Peter Freyther
5c0132882a nat: Assign the connection inside the new helper function. 2010-03-29 15:14:15 +02:00
Holger Hans Peter Freyther
ed443e949e nat: Actually add the connection to the SCCP list of active connections
Add the connection to the list of active connections. Otherwise
we are not able to find the connection.
2010-03-29 15:03:54 +02:00
Holger Hans Peter Freyther
1df69f3c64 filter: Move logging level down to INFO 2010-03-29 14:59:59 +02:00
Holger Hans Peter Freyther
d7cafafeee debug: Fix debugging for the nat category. 2010-03-29 14:59:21 +02:00
Holger Hans Peter Freyther
e09348d366 nat: Compare the IPA size with the actual size of the data...
One sanity check that was needed in my test case..
2010-03-29 14:58:43 +02:00
Holger Hans Peter Freyther
5f1b7c14f5 nat: Move creation of the structs to a separate file
This way one can create the bsc_nat structure in unit tests..
2010-03-29 12:48:36 +02:00
Holger Hans Peter Freyther
5b3e9198f0 nat: Move SCCP patching to a new file, log updates
Move patching and reassigning of messages to a new file which
will making testing this functionality more easy.
2010-03-29 11:04:52 +02:00
Holger Hans Peter Freyther
f0b21dfd25 bsc_msc: Handle the loss of the MSC connection better
Instead of simply exiting the application we will handle it by
giving up all SCCP connections, once we have the MSC back we will
send a GSM 08.08 reset message, and we will free all resources
related to these connections. This includes the primary and secondary
lchan of these connections.

While we are not connected to the MSC we will handle each message
that would open a SCCP connection by giving up the lchan. This has
only been compile tested and will need to be manually tested during
a test session.

This also highlights a DoS that could be used against OpenBSC
by setting up a lchan but never send any GSM L3 message. We will have
to fix that at some point.
2010-03-29 10:09:27 +02:00
Holger Hans Peter Freyther
e165d1aaa4 [misc] Clean some whitespace in files of this branch. 2010-03-29 08:10:48 +02:00
Holger Hans Peter Freyther
649496eb57 nat: Handle MSC disconnect by closing all NAT connections
When we disconnect from the MSC handle it by pushing the problem
to our connected clients. We will simply close all connections,
reject all new BSC connections and attempt to reconnect to the MSC.
2010-03-29 08:09:29 +02:00
Holger Hans Peter Freyther
135a45c833 msc: Create a real interface for BSC MSC and start handling reconnects
Create a BSC<->MSC interface and use it for the BSC MSC IP and the
BSC NAT to reduce code duplication on handling reconnects to the MSC
and cleaning up the local state. The code is only partially tested
and will contain bugs. Currently both the BSC and the NAT will just
exit on connection loss and this way have the current behavior.
2010-03-26 12:14:37 +01:00
Holger Hans Peter Freyther
1a3d9dbabf bsc_msc: Connect in a non blocking way to the MSC
The latency of setting up of the TCP connection can be quite high,
it is better to connect in a non blocking way. This code is working
by setting the socket nonblocking and temporarily replacing the
bfd callback with the connect handling.
Once the OS has connected our socket we switch back to normal operation.
2010-03-26 10:41:20 +01:00
Holger Hans Peter Freyther
a91d15df7e bsc_msc_ip: Keep track of active connections so we could clear them.
Keep track of SCCP connections so we can clear them
when the MSC is going down.
2010-03-26 09:58:40 +01:00
Holger Hans Peter Freyther
3368e2a3d1 nat: Add a warning for an important todo item on connection loss
In case we disconnect with some pending operations we will need to
signal the MSC that something is wrong. This could be by sending a
RLSD directly, or a clear command. Another part of the fix is to
respond with a RLC on unknown RLSD messages.
2010-03-26 09:28:40 +01:00
Holger Hans Peter Freyther
929d788e21 nat: Clear all pending messages in case the BSC disconnected
Throw away all messages we have scheduled but never delivered
to the BSC.
2010-03-26 09:27:08 +01:00
Holger Hans Peter Freyther
6958065f85 nat: Switch downstream over to the write queue 2010-03-26 09:18:02 +01:00
Holger Hans Peter Freyther
097c82b2bc nat: Stop using the input/ipaccess.c method as it will write directly
We want to write everything through the write queue, it seemed the
easiest to copy the bytes here and feed the data into the bsc_write
method.
2010-03-26 07:41:54 +01:00
Holger Hans Peter Freyther
abaeb3f55f nat: Make it clear where we want to send these methods 2010-03-26 07:26:18 +01:00
Holger Hans Peter Freyther
f42e29c79c nat: Move one more area to the bsc_write method 2010-03-26 07:24:34 +01:00
Holger Hans Peter Freyther
3177580cc1 nat: Move BSC msg sending to a new method.
Move all writes into one place so we can switch to the
write queue more easily in the future.
2010-03-26 07:20:59 +01:00
Holger Hans Peter Freyther
cbe77e1657 nat: Start using a write_queue for the BSC connection
We are still writing to the BSC directly and don't make real
use of this feature right now but we will need to do it.
2010-03-26 07:10:22 +01:00
Holger Hans Peter Freyther
3cedc4738f nat: Move MSC write to the write_queue and make it non blocking
Move the MSC code to a non blocking write.
2010-03-26 07:01:28 +01:00
Holger Hans Peter Freyther
0834fd9b85 nat: Rename variable from connection to listen
This is the socket we listen for incoming BSCs.
2010-03-26 06:51:04 +01:00
Holger Hans Peter Freyther
7b65c986eb bsc_msc_ip: Convert the MSC connection to the write queue
The SCCP stack was changed to give the ownership of the msgb
to the system integration, this allows us to use the stock write
queue to queue the write and write the msg to the MSC once we
are connected again.
2010-03-26 06:41:54 +01:00
Holger Hans Peter Freyther
17d751531e Merge branch 'on-waves/sccp' into on-waves/bsc-master 2010-03-26 05:49:34 +01:00
Holger Hans Peter Freyther
facb5cdfc2 channel requests: Add configuration to handle paging any with TCH
It is possible that the MSC is not sending the channel type it
needs for the operations it wants to do. Add a configuration option
to assign a TCH in case of paging any requests. It can be a good
idea to leave SDCCHs free for location updating requests.
2010-03-25 05:15:09 +01:00
Holger Hans Peter Freyther
aebea482f5 channel request: Store the to be assigned channel type in the GSM Network
Store the mapping from request to channel type in the GSM Network
struct as there is some policy involved with handling the request.

E.g. in a half rate network we don't want emergy calls to be getting
a TCH/F, or we want to have a different policy for early/late assignment
of phone calls.

Update the table when creating the network and when the neci is changed.
2010-03-25 04:58:08 +01:00
Holger Hans Peter Freyther
12f20d369c bsc_msc_ip: Add an option for the global log level 2010-03-25 03:01:24 +01:00
Holger Hans Peter Freyther
2008d3f54c Merge remote branch 'origin/master' into on-waves/bsc-master 2010-03-25 02:58:57 +01:00
Holger Hans Peter Freyther
a26ebe40f5 bssap: Allow to submit a SMS on the TCH
Similar to the bsc_rll.c code we need to indicate if we want to
send the data on the SACH or on the normal signalling link. For
CC and any other SAPI=0 usage this bits must be zero, whener we
try to do something with SMS this bit needs to be set to one.
2010-03-24 14:21:03 +01:00
Holger Hans Peter Freyther
a52f1cacb3 Merge remote branch 'origin/master' into on-waves/bsc-master 2010-03-24 14:16:16 +01:00
Holger Hans Peter Freyther
f5e71415a2 Merge remote branch 'origin/master' into on-waves/bsc-master 2010-03-24 11:23:01 +01:00
Holger Hans Peter Freyther
82a8d6e393 Specify a release reason for the lchan
In case the put_lchan is making the refcount drop to zero use the
release reason specified in the put_lchan call. This is used by the
BSC MSC IP implementation for the assignment handling where the old
channel is getting closed with a local end release (1).
2010-03-24 10:45:07 +01:00
Holger Hans Peter Freyther
1226c93937 Fix DNAT debug.h definition and move it to the enum. 2010-03-24 10:30:37 +01:00
Holger Hans Peter Freyther
b9c520f9b3 Merge remote branch 'origin/master' into on-waves/bsc-master
Keep a static version as the shell script is not dealing well
with branch tags/names containing text.

Resolve merge conflict in the Makefile.am by adding both sides
to the list of sources for the libbsc.a

Conflicts:
	openbsc/configure.in
	openbsc/src/Makefile.am
2010-03-24 10:28:43 +01:00
Holger Hans Peter Freyther
8a7ca57d3e bssap.c: Handle an assignment failure correctly
This method should return !0 in case of an failure so
we can send an assignment reject right away.
2010-03-24 10:27:04 +01:00
Holger Hans Peter Freyther
29f9f9fc79 Bump the local version to 0.3.90 in preparation for a 0.4.0 release 2010-03-24 10:13:23 +01:00
Holger Hans Peter Freyther
d512e454b3 Correct the company name. It should be On-Waves (ehf) 2010-03-24 06:16:24 +01:00
Holger Hans Peter Freyther
22481bf76d Merge remote branch 'origin/master' into on-waves/bsc-master
* Move to libosmocore
* Move to new debugging architecture
* Register the BTS types
* Has only been compile tested

Conflicts:
	openbsc/include/openbsc/Makefile.am
	openbsc/include/openbsc/gsm_data.h
	openbsc/include/openbsc/ipaccess.h
	openbsc/include/openbsc/mgcp.h
	openbsc/include/openbsc/msgb.h
	openbsc/include/openbsc/tlv.h
	openbsc/src/Makefile.am
	openbsc/src/abis_rsl.c
	openbsc/src/bsc_init.c
	openbsc/src/bsc_mgcp.c
	openbsc/src/chan_alloc.c
	openbsc/src/debug.c
	openbsc/src/gsm_subscriber_base.c
	openbsc/src/msgb.c
	openbsc/src/rest_octets.c
	openbsc/src/sccp/sccp.c
	openbsc/src/vty/command.c
	openbsc/src/vty_interface.c
	openbsc/tests/Makefile.am
2010-03-24 06:16:04 +01:00
Holger Hans Peter Freyther
b973955295 [msc/nat] It is better to use msgb_free to free the msgb
msgb_free is currently calling talloc_free but this might
change in the future and then this code would break..
2010-02-13 01:37:36 +01:00
Holger Hans Peter Freyther
9d51a36528 [nat/bsc] Fix memory leak of IPA messages...
* The read_msg method is allocating the msgb and we will
  need to free it once we are done with it.
2010-02-13 00:42:21 +01:00
Holger Hans Peter Freyther
ba3bbe55c1 [nat] Add configuration file for the bsc nat. 2010-02-12 22:26:45 +01:00
Holger Hans Peter Freyther
0619478073 [nat] Intercept the PAGING message and then forward it to the BSCs with that LAC
* Provide access to the GSM0808 TLV attributes so we can use it in
  the nat code.
* Read the PAGING message, if it is paged by LAC we go through each
  LAC and then attempt to find the proper BSC connection and then
  send the message to that BSC.
2010-02-09 17:35:09 +01:00
Holger Hans Peter Freyther
f8f184edab [nat] Fix compiler warning.. 2010-02-09 16:30:53 +01:00
Holger Hans Peter Freyther
d838951302 [nat] Implement token based identification.
Based on the token the NAT/MUX is capable of figuring out
which LAC this BSC is supposed to satisfy. This will be
needed for messages like paging that can be done by LAC.
2010-02-09 16:30:38 +01:00
Holger Hans Peter Freyther
f8e1b45a78 [tlv] Implement a variant for the IDTAG list for the IPA
Implement a helper that will allow to easily fill the
tag list with data.
2010-02-09 16:26:49 +01:00
Holger Hans Peter Freyther
dd2c9fdbcf [bsc] Allow to set a EGSM900, RGSM900 ARFCN
For R-GSM900 the channels 955-1023 are within the 900er band. The
System Information Type generation can not cope with these channels yet.
2010-02-09 15:44:14 +01:00
Holger Hans Peter Freyther
9991421cfb [ipaccess] Make the IPA version of LTV public. 2010-02-09 14:37:23 +01:00
Holger Hans Peter Freyther
e30f0e1c75 [nat] Do not forward messages from and to BSC when it is not authenticated
* Start using the authenticated bit in the BSC connection. This means
  that currently no messages are forwarded to the MSC from unauthenticated
  BSCs.
2010-02-08 23:24:32 +01:00
Holger Hans Peter Freyther
18598ff66d [nat] Use default handler for SIGINT to quit the app 2010-02-08 23:23:54 +01:00
Holger Hans Peter Freyther
8882c9e3a8 Merge commit 'on-waves/0.3.1' into on-waves/bsc-master 2010-02-08 20:20:27 +01:00
Holger Hans Peter Freyther
fdc64f6806 [bsc_msc_ip] Fix the re-queuing of packets...
* The MSC is sending us the next 04.08 packet before we have
  received the answer for the cipher model complete. The code was
  supposed to copy all packets from the current queue, to a new
  queue and then send the packets again.
* This would (re)establish the different SAPIs. Now the requeuing
  code was grabbing the packet from the empty queue (NULL pointer)
  and we were dereferencing it. It appears that we need to use
  "head" until the queue is empty.
2010-02-08 20:14:53 +01:00
Holger Hans Peter Freyther
16b331d14f Merge commit 'on-waves/0.3' into on-waves/bsc-master 2010-02-08 15:46:17 +01:00
Holger Hans Peter Freyther
ab46372e2a Bump the configure.in to 0.3on-wave. 2010-02-08 15:39:07 +01:00
Holger Hans Peter Freyther
be807e4250 [nat] Add VTY support to the BSC nat application
* Create struct bsc_nat and move the various lists into this structure
* Create the VTY code
* Call the VTY init and parsing code
* Create functions to create the types..
* Add some stuff into the bsc_connection to be used for the NAT with
  proper config files. E.g. to close the connection if the BSC does not
  respond to a given command.
2010-02-08 13:44:48 +01:00
Holger Hans Peter Freyther
71ddbf5c4f [telnet] Remove ancient #define... 2010-02-07 13:16:03 +01:00
Holger Hans Peter Freyther
63bb29fac0 [nat] Move the structs to the header file
This way the VTY code can use the structures to implement
the show functionality.
2010-02-07 13:08:09 +01:00
Holger Hans Peter Freyther
04b4f915a7 [ipa] Make sending of ID REQ public...
Make sending of the ID Request message public. We are going
to use this in the BSC NAT code to ask for querying the BSC.
2010-02-07 12:04:07 +01:00
Holger Hans Peter Freyther
4d95ab2231 [vty] Add a config for a simple OpenBSC BSC token
We will use this token to identify us at the MSC for
now. This assumes that something like OpenVPN is already
used to secure the networking. In the future we will
explore using TLS for the communication and certificates
for the authentication.
2010-02-07 11:45:55 +01:00
Holger Hans Peter Freyther
17944f7285 [nat] Add missing Makefile.am.. 2010-02-04 19:24:43 +01:00
Holger Hans Peter Freyther
d2964b6cd1 [nat] Make some methods static. 2010-01-31 13:52:32 +01:00
Holger Hans Peter Freyther
1ce5d7c8b7 [nat] Begin to patch SCCP connections
For the one MSC and n BSC case we need to patch the SCCP source
local reference on connection orientated links to avoid a clash.

For simple UDT packages we just let them pass and for SCCP connection
we have to:
    1.) Create an entry on Connection Request
    2.) Patch the entry on Connection Confirm, Connection Refuse,
        Connection Release, DT1, Connect Release Complete
    3.) Remove the entry on Connection Release Complete

The current code is blocking CRs, Release Complete from the MSC, and
creates the connection state only from the BSC side. The code to
assign a source reference is taken from sccp.c and handles wrap
arounds and such properly. We rely on the SCCP parser to fill out the
place to the source reference correctly so we can easily fix it.

The whole code is young and might contain bugs we need to resolve..
2010-01-31 09:46:21 +01:00
Holger Hans Peter Freyther
846457b10a [nat] Send a GSM 08.08 Reset Ack to the BSC...
When the reset was filtered out to the MSC we will respond
with a GSM08.08 reset ack right away. We are using a static
acknowledge here.
2010-01-30 12:45:10 +01:00
Holger Hans Peter Freyther
e7b9771c4d [nat] Specify the direction of the message
Do not run into the situation where we need to filter in one
direction but it should not be filtered..
2010-01-30 11:53:30 +01:00
Holger Hans Peter Freyther
d709900efa [sccp] Slightly improve the log message 2010-01-30 10:34:18 +01:00
Holger Hans Peter Freyther
55b4f5cc2e [nat] Prepare more sophisicated filtering and patching
Introduce a bsc_nat_parse method to parse a IP Access method
into various parts. Write out the IPA Proto, in case SCCP is used,
store the msg type, pointers to the source/dest local reference and
other information.

Use the result of bsc_nat_parse inside the bsc_nat_filter method
to decide if the message should be dropped or not.

In the future the bsc_nat_parse result will be used for patching
SCCP references and other parts of the message.

The filter language should be able to filter the msg type of SCCP
messages and gain the "NOT" word in the filter language.
2010-01-30 10:33:07 +01:00
Holger Hans Peter Freyther
1ac5ac75a9 [nat] Make use of the LOGP macro in the code base. 2010-01-29 05:58:43 +01:00
Holger Hans Peter Freyther
5cf38ed1ab [nat] Add debug area for the NAT code
This is going to give a conflict when merging with master but
it can be easily resolved by adding a new id then.
2010-01-29 05:49:06 +01:00
Holger Hans Peter Freyther
35d1531089 [sccp] Implement sccp_parse_header to be used by the NAT code. 2010-01-29 04:31:51 +01:00
Holger Hans Peter Freyther
47e3777caa [sccp] Split Connection DT1 into two parts
This is the last of supported messages to be split into a parse
and handle routine. Now all parse routines can be used by the NAT.
2010-01-29 04:31:00 +01:00
Holger Hans Peter Freyther
710f3c615c [sccp] Split Connection Release Complete into two parts 2010-01-29 04:19:56 +01:00
Holger Hans Peter Freyther
3111560e8a [sccp] Split Connection Confirm handling into two parts 2010-01-29 04:03:00 +01:00
Holger Hans Peter Freyther
7396afbba4 [sccp] Split Connection Refused into two parts 2010-01-29 03:58:12 +01:00
Holger Hans Peter Freyther
52a72e217e [sccp] Split Connection Released into two parts
Split the Connection Released into header parsing and into
acting on the parsed result. This is part of the NAT work.
2010-01-29 03:49:32 +01:00
Holger Hans Peter Freyther
ff0a562f9a Revert "[bssap] Open a traffic channel for the paging any reason"
This reverts commit 55a0716da7.

Using a TCH/H, TCH/F for paging purpose any will break the MT-SMS
case because this needs a SDCCH to establish SAPI=3. The On Waves
BSC Master branch has support for early assignment now so this hack
is not needed anymore.
2010-01-28 11:59:52 +01:00
Holger Hans Peter Freyther
556008d724 [bsc] Implement early assignment for CC for the MT case.
In case we need to handle speech but we are currently on a SDCCH
we need to assign a new channel and close the old one. This
implementation should have the correct flow of things but we might
need to fix some error situations properly.

It is implemented by keeping a secondary_lchan pointer that will
be swapped into the lchan pointer after the assignment complete
message from the MS. The old lchan will be deactivated (the SACCH
should stay open). We have to manually remove the subscr from the
lchan structure to properly close things down.
2010-01-28 11:59:51 +01:00
Holger Hans Peter Freyther
0094f84f30 [bssap] Use switch/case for the signal handler
Use switch/case, switch/case for the subsys and signal
to prepare to handle more signals in the future.
2010-01-28 11:59:51 +01:00
Holger Hans Peter Freyther
86069143ff [gsm48] Use optional Chan Mode 1 for the assignment command
Specify how we intend to use the assigned channel. This is
needed to make CC with early assignment work properly.
2010-01-28 11:59:51 +01:00
Holger Hans Peter Freyther
44f0be88a3 [gsm48] Allow to send the assignment command on a different lchan
Change the signature to take the lchan were the message is supposed
to be sent and the lchan which is supposed to be assigned.
2010-01-28 11:59:51 +01:00
Holger Hans Peter Freyther
5d88b372d7 [rsl] Send the MultiRateConfig in the RSL Channel Activate msg
If the lchan has AMR as speech codec we also need to send the
multirate config IE in the channel activation. This is already
done for the RSL Channel Modify message.
2010-01-28 04:46:32 +01:00
Holger Hans Peter Freyther
71c7bf5907 [sccp] Separate connection parsing and policy for connection request
The same concept as with the previous patch, make the reject method
work on the source local reference instead of passing it the header.
2010-01-27 12:31:50 +01:00
Holger Hans Peter Freyther
869033148c [sccp] Move the UDT parsing to a new method
Separate SCCP UDT parsing and handling into two methods. This
way the parsing can be reused by the BSC NAT.
2010-01-27 12:31:50 +01:00
Holger Hans Peter Freyther
bc0f7c0988 [sccp] Invent new API to be used by the BSC NAT
I want to reuse the SCCP code for header parsing in the BSC
NAT to identify data and patch the source local reference. To do
this the current handle_* methods will be changed into two parts
one is strictly parsing the other is handling the parsed data.
2010-01-27 12:31:50 +01:00
Holger Hans Peter Freyther
7d06063cfb [paging] Increase the time used to send paging messages to the BTS
Send a Paging Request to the BTS every two seconds. This way it is
unlikely that a phone will try to respond to two paging requests as
it is currently happening.
2010-01-27 12:31:50 +01:00
Holger Hans Peter Freyther
4e42b637fd [bsc_msc] Start the Inactivity Timer only when the connection is established
Start the SCCP IT timer only after the MSC has confirmed the SCCP
connection. It is safe to call bsc_del_timer even if it was never
started. This could happen on a connection refusal.
2010-01-27 12:31:50 +01:00
Holger Hans Peter Freyther
f44de9942b [msc] Fix compilation by adding blocked_gsm to the struct 2010-01-27 12:31:50 +01:00
Holger Hans Peter Freyther
3a110ae60b [msc] Attempt to fix MT SMS with ciphering enabled.
The MSC is asking us to enable ciphering and then immediately
sends a DTAP msg for SAPI=3. We handle this correctly by attempting
to establish SAPI=3 but we never get an establishment confirm
for this SAPI.

Attempt to fix it by not sending any DTAP message when we receive
the Cipher Mode Request and unblock the queue when the ciphering
is confirmed. The unblocking currently works by taking all messages
out of the queue and then submitting them again. This will attempt
to establish the SAPI=3 and such automaticaly.

And the MSC stopped sending me SMS so this needs to be verified at a
later time.
2010-01-27 07:34:34 +01:00
Holger Hans Peter Freyther
bb84adc465 [rest_octets] Change data_len to the sizes of the spec
Is that right?
2010-01-27 06:10:43 +01:00
Holger Hans Peter Freyther
8d123ea3c0 [system_information] Initialize the buffer before moving it
In the case of ipaccess we are doing a ++output but then still
try to write 23 bytes into it and on my system this is leading
to a stack corruption.
2010-01-27 06:09:36 +01:00
Holger Hans Peter Freyther
88ca894df7 [nat] Handle write errors with a warning to make the compiler happy
Make the compiler happy by checking the write error and printing
a message to the console.
2010-01-25 10:01:30 +01:00
Holger Hans Peter Freyther
42b0d6b494 [nat] Add a bsc_filter.c which will carry out the analysis and filtering
The first part is to analyze the IP Access Header and only forward
SCCP messages for now. In the future we might want to do MGCP
signalling through this protocol and connection as well and need to
update this then.
2010-01-21 08:52:40 +01:00
Holger Hans Peter Freyther
82d8b0457b [mgcp] In forward mode we need to rediscover the BTS more often
In plain forward mode we don't have DLCX which will clean
and reset the configuration. We will need to remember the
last GSM BTS port and send data to it.
2010-01-14 08:35:57 +01:00
Holger Hans Peter Freyther
433d6ee1a2 [mgcp] Handle BTS and NET being on the same host
* Do not only check the IP but also the port to figure out
  where to send the data
* Do not memset the endp->remote inside the bind_rtp but from
  inside the crcx as this will be modified by the MDCX
2010-01-14 00:15:44 +01:00
Holger Hans Peter Freyther
203a6eddf8 [mgcp] Warn about unknown messages... 2010-01-13 23:53:59 +01:00
Holger Hans Peter Freyther
56ef6249e3 [mgcp] Allow to forward to a different port 2010-01-13 23:36:53 +01:00
Holger Hans Peter Freyther
b2a96b1be7 [mgcp] Rename rtp and rtcp variables to net_rtp and net_rtcp
Rename the variables to refer to the fact that they are
the ports of the remote.

So we have:
    rtp_port as the local address we are binding to
    net_rtp  for the network rtp
    bsc_rtp  for the bsc rtp
2010-01-13 22:49:55 +01:00
Holger Hans Peter Freyther
d4c29c1574 [mgcp] Make it possible to not specify a bts ip
This way the mgcp will allow anyone to be the BTS..
in the future we might need to communicate things
properly between BSC and MGCP.
2010-01-13 16:38:18 +01:00
Holger Hans Peter Freyther
3d947e6d67 [nat] Use the right len for the packages.. 2010-01-13 15:22:20 +01:00
Holger Hans Peter Freyther
b62c9a19cf [sccp] Add a utility for the nat..
Add a small helper to determine the type of a message
2010-01-13 09:55:43 +01:00
Holger Hans Peter Freyther
ff5957568f [nat] Really forward the data to the BSC 2010-01-13 09:55:20 +01:00
Holger Hans Peter Freyther
7d2e1ca4be [nat] Make sure the ipaccess_bsc_cb will be called.. 2010-01-13 09:52:29 +01:00
Holger Hans Peter Freyther
7ce2e0c8b0 [nat] Unregister the fd before leaving.. 2010-01-13 09:51:23 +01:00
Holger Hans Peter Freyther
78d442420b [nat] First code to simply forward data from the MSC to the real BSC
First code to simply forward the data, no filtering or patching
is in place. This will need to happen soon.
2010-01-13 09:28:12 +01:00
Holger Hans Peter Freyther
8cd2709ebf [ipaccess] Create a method to send the ID ACK messages 2010-01-13 09:06:46 +01:00
Holger Hans Peter Freyther
41a1780102 [nat] Turn off compiler warning... 2010-01-12 21:36:08 +01:00
Holger Hans Peter Freyther
2f84715984 [nat] Security will become important at some point... 2010-01-12 21:35:32 +01:00
Holger Hans Peter Freyther
7253154fc5 [nat] Start to listen for the incoming BTS 2010-01-12 21:34:54 +01:00
Holger Hans Peter Freyther
6c1c76683f [nat] Connect to the MSC like the real BSC
Use the connect_to_msc method to connect to the MSC and
create structure to handle and forward messages to the
real BSC.
2010-01-12 21:15:08 +01:00
Holger Hans Peter Freyther
a92fe9a4ca [bsc_msc] Move the connect to the MSC routine into a new file 2010-01-12 20:40:39 +01:00
Holger Hans Peter Freyther
e83a3f584e [bsc-nat] Start with a simple NAT/MUX for a BSC
Harald actually pointed out that this feature is just NAT. We want
to connect n-real BSCs to one BSC Mux. We will talk the ip.access
protocol and SCCP over of this link.

The mux will drop certain GSM messages (like the reset), it will
replace source local reference (NAT functionality) and it will handle
some GSM08.08 specially.

Get the thing started...
2010-01-11 23:01:16 +01:00
Holger Hans Peter Freyther
118ddebc36 [on-waves] Use a default rtp_base_port, write it out in the config
Currently "write memory" will not store the rtp_base_port of the
network. Fix that by writing it out in write_net. Also set it to
4000 by default in the MGCP and in the BSC.
2010-01-08 15:24:21 +01:00
Holger Hans Peter Freyther
bb53004d47 Tag on-waves 0.2 release 2010-01-07 15:12:23 +01:00
Holger Hans Peter Freyther
6af20842cb [bssap] Return u_int16_t from the get_*_code methods
The LAI generation wants to have 16bit unsigned, just keep
them like this already. This means the int32_t will be truncated
inside the get_*_code methods which is better than doing it
somewhere else.
2010-01-07 14:53:18 +01:00
Holger Hans Peter Freyther
cc41cb07e7 [bssap] More brown paper... Make variables really signed
-1 is assigned in case the variables are not set. This means
it must be a signed type (as the comment says), now really use
a signed type.
2010-01-07 14:52:35 +01:00
Holger Hans Peter Freyther
d6fb23523a [bssap] Fix brown paper bag... Keep the air id ...*sigh*
We want to use the real number on the Um... Using the core
network code is totally wrong in this scope...
2010-01-07 14:36:20 +01:00
Holger Hans Peter Freyther
2aa0b45cc0 [bssap] Allow to use a different country code too
* Be able to have a country code in the air but use a different
  country code when talking to the core network.
* Now both country and network code can be different on air and
  on the MSC communication.
2010-01-07 03:17:01 +01:00
Holger Hans Peter Freyther
619df61ad2 [rsl] Partial revert of the GSM speech mode for the nanoBTS
This is partially reverting 0603c9d9e5,
it is true that the ip.access Wireshark dissectors differentiate
TCH/H from TCH/F but in my test I'm unable to send RTP on to the
BTS. It might be that the RTP payload provided in the MDCX is not
the one it will accept with the 0x05 mode. More work needs to be
done to understand this, that is the reason it is comitted to the
on-waves's branch instead of master.
2010-01-06 11:44:26 +01:00
Holger Hans Peter Freyther
893ea65f38 [bsc_msc_ip] Turn the MNC hack into a config option
* Make it possible to have a different MNC in the RSL traffic
  than in the core network.
* Introduce the "core network code NUMBER" variable. If it is
  set this network code will be used in traffic with the MSC.
* Use the core_network_code number when sending a packet to
  the MSC
* Regenerate the LAI (this is where I could have a bug) when
  sending packets to the BTS.
* Add size checks.

This is not tested, I might got something wrong.
2010-01-05 13:57:45 +01:00
Holger Hans Peter Freyther
64b811f113 [bsc_mgcp] Set the right remote rtp and rtcp port
* It is the same as local endpoint port
2010-01-05 12:35:16 +01:00
Holger Hans Peter Freyther
91fc9bf862 [bsc_mgcp] Fix writing of the config file...
* Add the new forward audio option
2010-01-05 12:29:36 +01:00
Holger Hans Peter Freyther
111a58dd37 [bsc_mgcp] Print a message which mode is configured 2010-01-05 12:25:25 +01:00
Holger Hans Peter Freyther
d1a2563a74 [bsc_mgcp] Add a new forward only mode to the bsc_mgcp
With forward IP in the config and early bind on we will
simply forward RTP data on the endpoints from BTS to the
forward IP address.

This is implemented by disabling MGCP functionality when
a forward IP address was specified, setting the forward IP
in the endp->remote and assigning a ci != CI_UNUSED.

Early bind will make sure the sockets are created, the BSC FD's
are registered and then the normal dispatch code will
do the forwarding.
2010-01-05 12:21:36 +01:00
Holger Hans Peter Freyther
7d3ef919ce [bssap] Set the right GSM08.08 speech version indicator
* For half rate we also need to set the 3rd bit to one
* See GSM08.08 §3.2.2.51 and then §3.2.2.11
2010-01-05 04:18:16 +01:00
Holger Hans Peter Freyther
cba98d87d6 [misc] Move handover into libmsc.a
Handover is a high level decision, it can span multiple BSCs
and belongs mostly into the MSC domain.
2009-12-22 08:03:55 +01:00
Holger Hans Peter Freyther
5c18ad0829 Merge commit 'origin/master' into on-waves/bsc-master
Conflicts:
	openbsc/include/openbsc/Makefile.am
	openbsc/include/openbsc/gsm_data.h
	openbsc/src/Makefile.am
	openbsc/src/abis_rsl.c
	openbsc/src/chan_alloc.c
	openbsc/src/gsm_04_08.c
	openbsc/src/gsm_data.c
	openbsc/src/vty_interface.c

The biggest problem is the moving of the RTP code into
the RSL layer. This may break quite some things...
2009-12-22 08:02:13 +01:00
Holger Hans Peter Freyther
0d9ed87d5c [bsc_hack] Ignore the sigpipe...
We might read or write on the OML link when the BTS is
reset and will get SIGPIPE interrupt and be gone... Just
ignore the SIGPIPE we will get the "exception" on the next
run of bsc_select and kill the (old) OML link.
2009-12-06 04:32:27 +01:00
Harald Welte
ec7be0c969 move RTP socket information from timeslot to lchan
With ip.access, in case of TCH/H, we have one RTP stream for each half-slot
(lchan), not just one per on-air timeslot.  This is quite different from
a classic BTS where the TRAU frames of the two TCH/H channels would be
part of the same 16k sub-slot in a E1 timeslot.
2009-12-06 04:05:31 +01:00
Harald Welte
9be3347601 RSL: catch inconsistent parameters ofr channel_mode_from_lchan() 2009-12-06 04:03:55 +01:00
Harald Welte
3eef7b7d81 Assign default values for T3101 and T3113
Without those default values, old config files will no longer work
after commit 23975e718f
2009-12-06 04:03:23 +01:00
Holger Hans Peter Freyther
9de4a6daa9 Merge branch 'master' into on-waves/bsc-master
Conflicts:
	openbsc/src/abis_nm.c
	openbsc/src/bsc_init.c
	openbsc/src/vty_interface.c
2009-11-24 19:58:01 +01:00
Holger Hans Peter Freyther
851ace9f33 Merge branch 'master' into on-waves/bsc-master
Conflicts:
	openbsc/include/openbsc/Makefile.am
	openbsc/src/Makefile.am
2009-11-20 18:01:37 +01:00
Holger Hans Peter Freyther
d1dd069b48 [configure] Add onwaves to the version tag 2009-11-20 17:43:40 +01:00
Holger Hans Peter Freyther
401db32ca2 HACK patch the network code..
Report to the MSC with the right code and patch
it on the air...
2009-11-20 17:41:05 +01:00
Holger Hans Peter Freyther
17e03d21d2 [vty] Add option to disable RF on a given TRX.
- Make sure that on runtime the Radio Carrier can be
  locked and unlocked. The vty code calls into the
  Abis NM to lock/unlock the channel and the state is
  stored there.

- Make sure that on start the Radio Carries remains
  offline and we are not starting it. On start the
  radio carrier is either locked or unlocked. This means
  the RSL will not connect until the RF is unlocked. It
  will connect then. To see RSL bringup failures one
  needs to parse the RSL nack message.
2009-11-20 17:40:50 +01:00
Holger Hans Peter Freyther
26a9bff201 [bsc_init] Activate the RC and the RSL link from the Software Activated Callback
On cold start the RSL link will not be brought up. Wait for the
Software to be Activated before starting the RSL link. This is
working reliable on the BTS I have tested with.
2009-11-20 17:40:39 +01:00
Holger Hans Peter Freyther
80fb260a60 [lchan] Release the channel ones its' usecount drops to zero
Remove the timer handling from the LCHAN and release the
channel ones the use count is dropping to zero.

Change code that was sending/using the lchan after the
release and change the send data method to warn in case
the lchan is used after it has been freed.
2009-11-20 17:40:28 +01:00
Holger Hans Peter Freyther
55a0716da7 [bssap] Open a traffic channel for the paging any reason
In the case the MS is requesting a channel with the
paging any channel reason, use a TCH. This allows us
to keep using very early assignment and the SDCCHs are
kept free for location updating requests.
2009-11-20 17:40:00 +01:00
Holger Hans Peter Freyther
c88fb75616 [rsl] Speculative crash fix in the RSL rcv message
The theory is that the BTS is almost dead and sends out
a incomplete message and we crash with that. I have not
been able to completely verify that.
2009-11-20 17:38:47 +01:00
Holger Hans Peter Freyther
d55a4dc326 Merge branch 'on-waves/gsm0808' into on-waves/bsc-master 2009-11-20 17:38:02 +01:00
Holger Hans Peter Freyther
a4e6f2e6e1 [bssap] Support multiple multiplexers in the assignment command
When more than one trunk group is allocated to the BSC the
MSC will start to assign channels from the different multiplexer.

We will map them the following way onto MGCP endpoints

Multiplex 0:
   0	->	1
   1	->      signalling
   2	->	2
   ..	->	..
   16	->	signalling (might be 15)
   30	->	30

Multiplex 1:
   0	->	31
   2	->	32
...

Multiplex 3:
..
2009-11-20 17:35:47 +01:00
Holger Hans Peter Freyther
7f71d99cc3 [bsc] Add a rtp base port to the BSC config too
Stop having a global variable... keep it in the
gsm network or the mgcp
2009-11-20 17:35:47 +01:00
Holger Hans Peter Freyther
b92167cf80 [vty] Write out BSC specific network parameters too 2009-11-20 17:35:47 +01:00
Holger Hans Peter Freyther
4b6a6dbe7e [bssap] Cope with weird channel mapping on the network side
The timeslot of the network maps the following way
	0	->	1
	1	->	n/a
	2	->	2
	...	->      ...
	31	->	31
2009-11-20 17:35:47 +01:00
Holger Hans Peter Freyther
763e8c7766 [ipacc] Add a way to override the rtp payload for MDCX 2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
823ff16088 [bsc] Send the SCCP IT message in a given interval
Send the message every 60 seconds on every SCCP
connection. The 60 seconds were taken from a protocol
trace obtained on the network.
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
6f93c6a1e0 [bsc] Unref the lchan when the MSC is closing the SCCP connection
Currently we are not sending the Inactivity Test message so the
MSC will close the specific sccp connection but we would keep the
lchan open and then end up with resource issues.

Change the code to close the lchan before closing the SCCP connection..
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
f97e48b0de [bssap] Send multirate config for HR AMR with 5.9k
Send a hardcoded multirate config when usin the
AMR codec. This should be more configurable in
the future.
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
761600b0fd [bsc] Add a test_mode function that can be used to inject packages
This method can be called from the main method to inject
a test message into a "fake" network with sccp connection.
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
8549462bc6 [bssap] Attempt to allow selecting the speech mode from config
It is possible to specify a list of possible speech codecs
and we will try to match the assignment command with the
one from the config file. This is not tested yet and we have
one problem. We assume we can modify the channel to hold
the speech value... this will require more work.
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
436e5c6308 [vty] Add configuration for the preferred speech version
Add network configuration option to specify which audio
codecs are supported by the BTS. This allows the BSC to
pick the audio codec in the GSM0808 Assignment Request.
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
f8b9d844c1 [bssap] Pick the A5/0 vs A5/1 setting from the gsm_network
Follow the configuration of the gsm network. If the Cipher
Mode Request does not allow our preferred format we will
reject it. Otherwise send the cipher mode command to the
mobile station. This code is mostly untested.
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
58ec07d580 [bsc] Add BSC specific config option... currently and empty show is implemented
In the future this should give a list of SCCP connections
and their allocated radio resources/users...
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
71465c21f4 [bssap] Implement generating a classmark update message
Generate a classmark update message from a given payload
this might need to be changed to get the version2 and
version3 parameters
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
16d0a833f8 [bssmap] Fix the chosen encryption in assignment complete
Send the RSL value... it is the right value
2009-11-20 17:35:46 +01:00
Holger Hans Peter Freyther
ea72b62cac [bssmap] Unconditionally include the chosen encryption in cipher mode complete 2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
49a84ec6e9 [bssmap] Assignment handling fixes and improvements
- Fix the generation of the assignment failure message
- Parse the permitted indicator of the assignment request message
2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
42c636b6c8 [bssap] Fix generation of the failure message 2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
a0a55f555e [bssap] Only start establish when the link is not yet established
This is fixing a bug when we try to submit a SMS from the MS to
the network. We send the RLS ESTABLISH REQUEST but as the MS
already established this SAPI we waited for the timeout and failed..
2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
23ed00e410 [bssap] Improve log messages... 2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
3fe910b9f1 [bssap] First go at implementing channel assignment... 2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
097bdeb77d [bssap] First go at implementing ASSIGNMENT REQUEST 2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
1b85de02e0 [bssap] Add a "#warning" that cipher mode is not properly handled 2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
2281d1835f [bssap] Start to queue messages to the BTS and to the MSC
For the MSC we need to queue GSM04.08 messages until the
SCCP connection is  confirmed to be open and then can send
the stored messages. The queue is limited to 10 messages
at which point new ones will be dropped. Currently the
only messages we get are measurement indication messages
but it is better to be safe than sorry.

The SCCP messages are sent as soon as the connection
is considered established and then no queueing happens
any more. While replacing sccp_connection_write calls
various memory leaks has been fixed.

For the MS we might have received a DTAP and need to do
an operation that requires a roundtrip and want to send
wait until this has happened. The two scenerios are sending
a SMS to the phone that requires to do something special
for the different SAPI. Currently it is assumed that
only one SAPI=0 -> SAPI=3 change happen during the connection.

For the first SAPI != 0 we will send the rll_ request
and then wait for the timeout or confirmation. In case
of timeout a SAPI "n" reject is sent and in case of
success the queue is getting emptied.
2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
fb4433a129 [bssap] Implement SAPI "N" Reject message
This message will be needed when no RLL connection
on a different SAPI can be established or we don't
want to establish it.
2009-11-20 17:35:45 +01:00
Holger Hans Peter Freyther
d954dcf9e1 [bsc_msc_ip] This is a BSC that connects to real MSC via IP
This is a BSC to be used by on-waves.com to connect to a real
MSC using SCCP over IP.

The following messages and features are currently implemented:
    - IPA identity ack's
    - COMPLETE LAYER3 INFORMATION
    - DTAP
    - PAGING COMMAND
    - CLEAR COMPLETE/CLEAR REQUEST
    - CIPHER MODE COMMAND/ REJECT /COMPLETE

It comes with a tool to create the enum's from the spec and
a very simple test server to do the handshaking.
2009-11-20 17:35:45 +01:00
60 changed files with 6951 additions and 418 deletions

View File

@@ -1,9 +1,7 @@
dnl Process this file with autoconf to produce a configure script
AC_INIT([openbsc],
m4_esyscmd([./git-version-gen .tarball-version]),
[openbsc-devel@lists.openbsc.org])
AC_INIT
AM_INIT_AUTOMAKE([dist-bzip2])
AM_INIT_AUTOMAKE(openbsc, 0.3.91onwaves)
dnl kernel style compile messages
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -54,4 +52,5 @@ AC_OUTPUT(
tests/db/Makefile
tests/channel/Makefile
tests/sccp/Makefile
tests/bsc-nat/Makefile
Makefile)

2
openbsc/contrib/README Normal file
View File

@@ -0,0 +1,2 @@
This contains a set of scripts used for the development of the
MSC functionality.

View File

@@ -10,7 +10,7 @@ rsip_resp = """200 321321332\r\n"""
audit_packet = """AUEP %d 13@mgw MGCP 1.0\r\n"""
crcx_packet = """CRCX %d 14@mgw MGCP 1.0\r\nC: 4a84ad5d25f\r\nL: p:20, a:GSM-EFR, nt:IN\r\nM: recvonly\r\n"""
dlcx_packet = """DLCX %d 14@mgw MGCP 1.0\r\nC: 4a84ad5d25f\r\nI: %d\r\n"""
mdcx_packet = """MDCX %d 14@mgw MGCP 1.0\r\nC: 4a84ad5d25f\r\nI: %d\r\nL: p:20, a:GSM-EFR, nt:IN\r\nM: recvonly\r\n\r\nv=0\r\no=- 258696477 0 IN IP4 172.16.1.107\r\ns=-\r\nc=IN IP4 172.16.1.107\r\nt=0 0\r\nm=audio 4400 RTP/AVP 127\r\na=rtpmap:127 GSM-EFR/8000/1\r\na=ptime:20\r\na=recvonly\r\nm=image 4402 udptl t38\r\na=T38FaxVersion:0\r\na=T38MaxBitRate:14400\r\n"""
mdcx_packet = """MDCX %d 14@mgw MGCP 1.0\r\nC: 4a84ad5d25f\r\nI: %d\r\nL: p:20, a:GSM-EFR, nt:IN\r\nM: recvonly\r\n\r\nv=0\r\no=- 258696477 0 IN IP4 172.16.1.107\r\ns=-\r\nc=IN IP4 172.16.1.107\r\nt=0 0\r\nm=audio 6666 RTP/AVP 127\r\na=rtpmap:127 GSM-EFR/8000/1\r\na=ptime:20\r\na=recvonly\r\nm=image 4402 udptl t38\r\na=T38FaxVersion:0\r\na=T38MaxBitRate:14400\r\n"""
def hexdump(src, length=8):
"""Recipe is from http://code.activestate.com/recipes/142812/"""
@@ -25,15 +25,24 @@ def hexdump(src, length=8):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(("127.0.0.1", MGCP_CALLAGENT_PORT))
server_socket.setblocking(0)
server_socket.setblocking(1)
def send_receive(packet):
last_ci = 1
def send_and_receive(packet):
global last_ci
server_socket.sendto(packet, ("127.0.0.1", MGCP_GATEWAY_PORT))
try:
data, addr = server_socket.recvfrom(4096)
# attempt to store the CI of the response
list = data.split("\n")
for item in list:
if item.startswith("I: "):
last_ci = int(item[3:])
print hexdump(data), addr
except socket.error:
except socket.error, e:
print e
pass
def generate_tid():
@@ -42,13 +51,10 @@ def generate_tid():
i = 1
while True:
send_receive(rsip_resp)
send_receive(audit_packet)
send_receive(crcx_packet % generate_tid() )
send_receive(mdcx_packet % (generate_tid(), i))
send_receive(dlcx_packet % (generate_tid(), i))
i = i + 1
send_and_receive(audit_packet % generate_tid())
send_and_receive(crcx_packet % generate_tid() )
send_and_receive(mdcx_packet % (generate_tid(), last_ci))
send_and_receive(dlcx_packet % (generate_tid(), last_ci))
time.sleep(3)

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python
import sys
# packages
ACK ="\x00\x01\xfe\x06"
RESET_ACK = "\x00\x13\xfd\x09\x00\x03\x07\x0b\x04\x43\x01\x00\xfe\x04\x43\x5c\x00\xfe\x03\x00\x01\x31"
PAGE = "\x00\x20\xfd\x09\x00\x03\x07\x0b\x04\x43\x01\x00\xfe\x04\x43\x5c\x00\xfe\x10\x00\x0e\x52\x08\x08\x29\x42\x08\x05\x03\x12\x23\x42\x1a\x01\x06"
# simple handshake...
sys.stdout.write(ACK)
sys.stdout.flush()
sys.stdin.read(4)
# wait for some data and send reset ack
sys.stdin.read(21)
sys.stdout.write(RESET_ACK)
sys.stdout.flush()
sys.stdout.write(RESET_ACK)
sys.stdout.flush()
# page a subscriber
sys.stdout.write(PAGE)
sys.stdout.flush()
while True:
sys.stdin.read(1)

View File

@@ -5,7 +5,8 @@ noinst_HEADERS = abis_nm.h abis_rsl.h db.h gsm_04_08.h gsm_data.h \
ipaccess.h rs232.h openbscdefines.h rtp_proxy.h \
bsc_rll.h mncc.h transaction.h ussd.h gsm_04_80.h \
silent_call.h mgcp.h meas_rep.h rest_octets.h \
system_information.h handover.h mgcp_internal.h
system_information.h handover.h mgcp_internal.h \
bssap.h bsc_msc.h bsc_nat.h vty.h
openbsc_HEADERS = gsm_04_08.h meas_rep.h
openbscdir = $(includedir)/openbsc

View File

@@ -68,7 +68,7 @@ unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
unsigned int n_pag_blocks(int bs_ccch_sdcch_comb, unsigned int bs_ag_blks_res);
u_int64_t str_to_imsi(const char *imsi_str);
u_int8_t lchan2chan_nr(const struct gsm_lchan *lchan);
int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id);
int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t release_reason);
/* to be provided by external code */
int abis_rsl_sendmsg(struct msgb *msg);

View File

@@ -0,0 +1,46 @@
/* Routines to talk to the MSC using the IPA Protocol */
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#ifndef BSC_MSC_H
#define BSC_MSC_H
#include <osmocore/write_queue.h>
#include <osmocore/timer.h>
struct bsc_msc_connection {
struct write_queue write_queue;
int is_connected;
const char *ip;
int port;
void (*connection_loss) (struct bsc_msc_connection *);
void (*connected) (struct bsc_msc_connection *);
struct timer_list reconnect_timer;
};
struct bsc_msc_connection *bsc_msc_create(const char *ip, int port);
int bsc_msc_connect(struct bsc_msc_connection *);
void bsc_msc_schedule_connect(struct bsc_msc_connection *);
void bsc_msc_lost(struct bsc_msc_connection *);
#endif

View File

@@ -0,0 +1,212 @@
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#ifndef BSC_NAT_H
#define BSC_NAT_H
#include "mgcp.h"
#include <sys/types.h>
#include <sccp/sccp_types.h>
#include <osmocore/select.h>
#include <osmocore/msgb.h>
#include <osmocore/timer.h>
#include <osmocore/write_queue.h>
#define DIR_BSC 1
#define DIR_MSC 2
#define NAT_IPAC_PROTO_MGCP 0xfc
struct bsc_nat;
/*
* For the NAT we will need to analyze and later patch
* the received message. This would require us to parse
* the IPA and SCCP header twice. Instead of doing this
* we will have one analyze structure and have the patching
* and filter operate on the same structure.
*/
struct bsc_nat_parsed {
/* ip access prototype */
int ipa_proto;
/* source local reference */
struct sccp_source_reference *src_local_ref;
/* destination local reference */
struct sccp_source_reference *dest_local_ref;
/* called ssn number */
int called_ssn;
/* calling ssn number */
int calling_ssn;
/* sccp message type */
int sccp_type;
/* bssap type, e.g. 0 for BSS Management */
int bssap;
/* the gsm0808 message type */
int gsm_type;
};
/*
* Per BSC data structure
*/
struct bsc_connection {
struct llist_head list_entry;
/* do we know anything about this BSC? */
int authenticated;
/* the fd we use to communicate */
struct write_queue write_queue;
/* the BSS associated */
struct bsc_config *cfg;
/* a timeout node */
struct timer_list id_timeout;
/* a back pointer */
struct bsc_nat *nat;
};
/*
* Per SCCP source local reference patch table. It needs to
* be updated on new SCCP connections, connection confirm and reject,
* and on the loss of the BSC connection.
*/
struct sccp_connections {
struct llist_head list_entry;
struct bsc_connection *bsc;
struct sccp_source_reference real_ref;
struct sccp_source_reference patched_ref;
struct sccp_source_reference remote_ref;
/* GSM audio handling. That is 32 * multiplex + ts */
int msc_timeslot;
int bsc_timeslot;
};
/**
* One BSC entry in the config
*/
struct bsc_config {
struct llist_head entry;
char *token;
unsigned int lac;
int nr;
struct bsc_nat *nat;
};
/**
* BSCs point of view of endpoints
*/
struct bsc_endpoint {
/* the pending transaction id */
char *transaction_id;
/* the bsc we are talking to */
struct bsc_connection *bsc;
/* pending delete */
int pending_delete;
};
/**
* the structure of the "nat" network
*/
struct bsc_nat {
/* active SCCP connections that need patching */
struct llist_head sccp_connections;
/* active BSC connections that need patching */
struct llist_head bsc_connections;
/* known BSC's */
struct llist_head bsc_configs;
int num_bsc;
/* MGCP config */
struct mgcp_config *mgcp_cfg;
struct write_queue mgcp_queue;
u_int8_t mgcp_msg[4096];
int mgcp_length;
struct bsc_endpoint *bsc_endpoints;
};
/* create and init the structures */
struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac);
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
struct bsc_nat *bsc_nat_alloc(void);
struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat);
void sccp_connection_destroy(struct sccp_connections *);
/**
* parse the given message into the above structure
*/
struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg);
/**
* filter based on IP Access header in both directions
*/
int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed);
int bsc_nat_vty_init(struct bsc_nat *nat);
struct bsc_connection *bsc_nat_find_bsc(struct bsc_nat *nat, struct msgb *msg);
/**
* SCCP patching and handling
*/
int create_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed);
int update_sccp_src_ref(struct sccp_connections *sccp, struct bsc_nat_parsed *parsed);
void remove_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed);
struct sccp_connections *patch_sccp_src_ref_to_bsc(struct msgb *, struct bsc_nat_parsed *, struct bsc_nat *);
struct sccp_connections *patch_sccp_src_ref_to_msc(struct msgb *, struct bsc_nat_parsed *, struct bsc_nat *);
/**
* MGCP/Audio handling
*/
int bsc_write_mgcp_msg(struct bsc_connection *bsc, struct msgb *msg);
int bsc_write_mgcp(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length);
int bsc_mgcp_assign(struct sccp_connections *, struct msgb *msg);
void bsc_mgcp_clear(struct sccp_connections *);
void bsc_mgcp_free_endpoint(struct bsc_nat *nat, int);
void bsc_mgcp_free_endpoints(struct bsc_nat *nat);
int bsc_mgcp_init(struct bsc_nat *nat);
struct bsc_connection *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number);
struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port);
void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg);
void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc);
int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]);
int bsc_mgcp_extract_ci(const char *resp);
#endif

View File

@@ -0,0 +1,336 @@
/* From GSM08.08 */
#ifndef BSSAP_H
#define BSSAP_H
#include <stdlib.h>
#include <osmocore/msgb.h>
#include <openbsc/gsm_data.h>
/*
* this is from GSM 03.03 CGI but is copied in GSM 08.08
* in § 3.2.2.27 for Cell Identifier List
*/
enum CELL_IDENT {
CELL_IDENT_WHOLE_GLOBAL = 0,
CELL_IDENT_LAC_AND_CI = 1,
CELL_IDENT_CI = 2,
CELL_IDENT_NO_CELL = 3,
CELL_IDENT_LAI_AND_LAC = 4,
CELL_IDENT_LAC = 5,
CELL_IDENT_BSS = 6,
CELL_IDENT_UTRAN_PLMN_LAC_RNC = 8,
CELL_IDENT_UTRAN_RNC = 9,
CELL_IDENT_UTRAN_LAC_RNC = 10,
};
/* GSM 08.06 § 6.3 */
enum BSSAP_MSG_TYPE {
BSSAP_MSG_BSS_MANAGEMENT = 0x0,
BSSAP_MSG_DTAP = 0x1,
};
struct bssmap_header {
u_int8_t type;
u_int8_t length;
} __attribute__((packed));
struct dtap_header {
u_int8_t type;
u_int8_t link_id;
u_int8_t length;
} __attribute__((packed));
enum BSS_MAP_MSG_TYPE {
BSS_MAP_MSG_RESERVED_0 = 0,
/* ASSIGNMENT MESSAGES */
BSS_MAP_MSG_ASSIGMENT_RQST = 1,
BSS_MAP_MSG_ASSIGMENT_COMPLETE = 2,
BSS_MAP_MSG_ASSIGMENT_FAILURE = 3,
/* HANDOVER MESSAGES */
BSS_MAP_MSG_HANDOVER_RQST = 16,
BSS_MAP_MSG_HANDOVER_REQUIRED = 17,
BSS_MAP_MSG_HANDOVER_RQST_ACKNOWLEDGE= 18,
BSS_MAP_MSG_HANDOVER_CMD = 19,
BSS_MAP_MSG_HANDOVER_COMPLETE = 20,
BSS_MAP_MSG_HANDOVER_SUCCEEDED = 21,
BSS_MAP_MSG_HANDOVER_FAILURE = 22,
BSS_MAP_MSG_HANDOVER_PERFORMED = 23,
BSS_MAP_MSG_HANDOVER_CANDIDATE_ENQUIRE = 24,
BSS_MAP_MSG_HANDOVER_CANDIDATE_RESPONSE = 25,
BSS_MAP_MSG_HANDOVER_REQUIRED_REJECT = 26,
BSS_MAP_MSG_HANDOVER_DETECT = 27,
/* RELEASE MESSAGES */
BSS_MAP_MSG_CLEAR_CMD = 32,
BSS_MAP_MSG_CLEAR_COMPLETE = 33,
BSS_MAP_MSG_CLEAR_RQST = 34,
BSS_MAP_MSG_RESERVED_1 = 35,
BSS_MAP_MSG_RESERVED_2 = 36,
BSS_MAP_MSG_SAPI_N_REJECT = 37,
BSS_MAP_MSG_CONFUSION = 38,
/* OTHER CONNECTION RELATED MESSAGES */
BSS_MAP_MSG_SUSPEND = 40,
BSS_MAP_MSG_RESUME = 41,
BSS_MAP_MSG_CONNECTION_ORIENTED_INFORMATION = 42,
BSS_MAP_MSG_PERFORM_LOCATION_RQST = 43,
BSS_MAP_MSG_LSA_INFORMATION = 44,
BSS_MAP_MSG_PERFORM_LOCATION_RESPONSE = 45,
BSS_MAP_MSG_PERFORM_LOCATION_ABORT = 46,
BSS_MAP_MSG_COMMON_ID = 47,
/* GENERAL MESSAGES */
BSS_MAP_MSG_RESET = 48,
BSS_MAP_MSG_RESET_ACKNOWLEDGE = 49,
BSS_MAP_MSG_OVERLOAD = 50,
BSS_MAP_MSG_RESERVED_3 = 51,
BSS_MAP_MSG_RESET_CIRCUIT = 52,
BSS_MAP_MSG_RESET_CIRCUIT_ACKNOWLEDGE = 53,
BSS_MAP_MSG_MSC_INVOKE_TRACE = 54,
BSS_MAP_MSG_BSS_INVOKE_TRACE = 55,
BSS_MAP_MSG_CONNECTIONLESS_INFORMATION = 58,
/* TERRESTRIAL RESOURCE MESSAGES */
BSS_MAP_MSG_BLOCK = 64,
BSS_MAP_MSG_BLOCKING_ACKNOWLEDGE = 65,
BSS_MAP_MSG_UNBLOCK = 66,
BSS_MAP_MSG_UNBLOCKING_ACKNOWLEDGE = 67,
BSS_MAP_MSG_CIRCUIT_GROUP_BLOCK = 68,
BSS_MAP_MSG_CIRCUIT_GROUP_BLOCKING_ACKNOWLEDGE = 69,
BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCK = 70,
BSS_MAP_MSG_CIRCUIT_GROUP_UNBLOCKING_ACKNOWLEDGE = 71,
BSS_MAP_MSG_UNEQUIPPED_CIRCUIT = 72,
BSS_MAP_MSG_CHANGE_CIRCUIT = 78,
BSS_MAP_MSG_CHANGE_CIRCUIT_ACKNOWLEDGE = 79,
/* RADIO RESOURCE MESSAGES */
BSS_MAP_MSG_RESOURCE_RQST = 80,
BSS_MAP_MSG_RESOURCE_INDICATION = 81,
BSS_MAP_MSG_PAGING = 82,
BSS_MAP_MSG_CIPHER_MODE_CMD = 83,
BSS_MAP_MSG_CLASSMARK_UPDATE = 84,
BSS_MAP_MSG_CIPHER_MODE_COMPLETE = 85,
BSS_MAP_MSG_QUEUING_INDICATION = 86,
BSS_MAP_MSG_COMPLETE_LAYER_3 = 87,
BSS_MAP_MSG_CLASSMARK_RQST = 88,
BSS_MAP_MSG_CIPHER_MODE_REJECT = 89,
BSS_MAP_MSG_LOAD_INDICATION = 90,
/* VGCS/VBS */
BSS_MAP_MSG_VGCS_VBS_SETUP = 4,
BSS_MAP_MSG_VGCS_VBS_SETUP_ACK = 5,
BSS_MAP_MSG_VGCS_VBS_SETUP_REFUSE = 6,
BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RQST = 7,
BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_RESULT = 28,
BSS_MAP_MSG_VGCS_VBS_ASSIGNMENT_FAILURE = 29,
BSS_MAP_MSG_VGCS_VBS_QUEUING_INDICATION = 30,
BSS_MAP_MSG_UPLINK_RQST = 31,
BSS_MAP_MSG_UPLINK_RQST_ACKNOWLEDGE = 39,
BSS_MAP_MSG_UPLINK_RQST_CONFIRMATION = 73,
BSS_MAP_MSG_UPLINK_RELEASE_INDICATION = 74,
BSS_MAP_MSG_UPLINK_REJECT_CMD = 75,
BSS_MAP_MSG_UPLINK_RELEASE_CMD = 76,
BSS_MAP_MSG_UPLINK_SEIZED_CMD = 77,
};
enum GSM0808_IE_CODING {
GSM0808_IE_CIRCUIT_IDENTITY_CODE = 1,
GSM0808_IE_RESERVED_0 = 2,
GSM0808_IE_RESOURCE_AVAILABLE = 3,
GSM0808_IE_CAUSE = 4,
GSM0808_IE_CELL_IDENTIFIER = 5,
GSM0808_IE_PRIORITY = 6,
GSM0808_IE_LAYER_3_HEADER_INFORMATION = 7,
GSM0808_IE_IMSI = 8,
GSM0808_IE_TMSI = 9,
GSM0808_IE_ENCRYPTION_INFORMATION = 10,
GSM0808_IE_CHANNEL_TYPE = 11,
GSM0808_IE_PERIODICITY = 12,
GSM0808_IE_EXTENDED_RESOURCE_INDICATOR = 13,
GSM0808_IE_NUMBER_OF_MSS = 14,
GSM0808_IE_RESERVED_1 = 15,
GSM0808_IE_RESERVED_2 = 16,
GSM0808_IE_RESERVED_3 = 17,
GSM0808_IE_CLASSMARK_INFORMATION_T2 = 18,
GSM0808_IE_CLASSMARK_INFORMATION_T3 = 19,
GSM0808_IE_INTERFERENCE_BAND_TO_USE = 20,
GSM0808_IE_RR_CAUSE = 21,
GSM0808_IE_RESERVED_4 = 22,
GSM0808_IE_LAYER_3_INFORMATION = 23,
GSM0808_IE_DLCI = 24,
GSM0808_IE_DOWNLINK_DTX_FLAG = 25,
GSM0808_IE_CELL_IDENTIFIER_LIST = 26,
GSM0808_IE_RESPONSE_RQST = 27,
GSM0808_IE_RESOURCE_INDICATION_METHOD = 28,
GSM0808_IE_CLASSMARK_INFORMATION_TYPE_1 = 29,
GSM0808_IE_CIRCUIT_IDENTITY_CODE_LIST = 30,
GSM0808_IE_DIAGNOSTIC = 31,
GSM0808_IE_LAYER_3_MESSAGE_CONTENTS = 32,
GSM0808_IE_CHOSEN_CHANNEL = 33,
GSM0808_IE_TOTAL_RESOURCE_ACCESSIBLE = 34,
GSM0808_IE_CIPHER_RESPONSE_MODE = 35,
GSM0808_IE_CHANNEL_NEEDED = 36,
GSM0808_IE_TRACE_TYPE = 37,
GSM0808_IE_TRIGGERID = 38,
GSM0808_IE_TRACE_REFERENCE = 39,
GSM0808_IE_TRANSACTIONID = 40,
GSM0808_IE_MOBILE_IDENTITY = 41,
GSM0808_IE_OMCID = 42,
GSM0808_IE_FORWARD_INDICATOR = 43,
GSM0808_IE_CHOSEN_ENCR_ALG = 44,
GSM0808_IE_CIRCUIT_POOL = 45,
GSM0808_IE_CIRCUIT_POOL_LIST = 46,
GSM0808_IE_TIME_INDICATION = 47,
GSM0808_IE_RESOURCE_SITUATION = 48,
GSM0808_IE_CURRENT_CHANNEL_TYPE_1 = 49,
GSM0808_IE_QUEUEING_INDICATOR = 50,
GSM0808_IE_SPEECH_VERSION = 64,
GSM0808_IE_ASSIGNMENT_REQUIREMENT = 51,
GSM0808_IE_TALKER_FLAG = 53,
GSM0808_IE_CONNECTION_RELEASE_RQSTED = 54,
GSM0808_IE_GROUP_CALL_REFERENCE = 55,
GSM0808_IE_EMLPP_PRIORITY = 56,
GSM0808_IE_CONFIG_EVO_INDI = 57,
GSM0808_IE_OLD_BSS_TO_NEW_BSS_INFORMATION = 58,
GSM0808_IE_LSA_IDENTIFIER = 59,
GSM0808_IE_LSA_IDENTIFIER_LIST = 60,
GSM0808_IE_LSA_INFORMATION = 61,
GSM0808_IE_LCS_QOS = 62,
GSM0808_IE_LSA_ACCESS_CTRL_SUPPR = 63,
GSM0808_IE_LCS_PRIORITY = 67,
GSM0808_IE_LOCATION_TYPE = 68,
GSM0808_IE_LOCATION_ESTIMATE = 69,
GSM0808_IE_POSITIONING_DATA = 70,
GSM0808_IE_LCS_CAUSE = 71,
GSM0808_IE_LCS_CLIENT_TYPE = 72,
GSM0808_IE_APDU = 73,
GSM0808_IE_NETWORK_ELEMENT_IDENTITY = 74,
GSM0808_IE_GPS_ASSISTANCE_DATA = 75,
GSM0808_IE_DECIPHERING_KEYS = 76,
GSM0808_IE_RETURN_ERROR_RQST = 77,
GSM0808_IE_RETURN_ERROR_CAUSE = 78,
GSM0808_IE_SEGMENTATION = 79,
GSM0808_IE_SERVICE_HANDOVER = 80,
GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_UMTS = 81,
GSM0808_IE_SOURCE_RNC_TO_TARGET_RNC_TRANSPARENT_CDMA2000= 82,
GSM0808_IE_RESERVED_5 = 65,
GSM0808_IE_RESERVED_6 = 66,
};
enum gsm0808_cause {
GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE = 0,
GSM0808_CAUSE_RADIO_INTERFACE_FAILURE = 1,
GSM0808_CAUSE_UPLINK_QUALITY = 2,
GSM0808_CAUSE_UPLINK_STRENGTH = 3,
GSM0808_CAUSE_DOWNLINK_QUALITY = 4,
GSM0808_CAUSE_DOWNLINK_STRENGTH = 5,
GSM0808_CAUSE_DISTANCE = 6,
GSM0808_CAUSE_O_AND_M_INTERVENTION = 7,
GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION = 8,
GSM0808_CAUSE_CALL_CONTROL = 9,
GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION = 10,
GSM0808_CAUSE_HANDOVER_SUCCESSFUL = 11,
GSM0808_CAUSE_BETTER_CELL = 12,
GSM0808_CAUSE_DIRECTED_RETRY = 13,
GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL = 14,
GSM0808_CAUSE_TRAFFIC = 15,
GSM0808_CAUSE_EQUIPMENT_FAILURE = 32,
GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE = 33,
GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE = 34,
GSM0808_CAUSE_CCCH_OVERLOAD = 35,
GSM0808_CAUSE_PROCESSOR_OVERLOAD = 36,
GSM0808_CAUSE_BSS_NOT_EQUIPPED = 37,
GSM0808_CAUSE_MS_NOT_EQUIPPED = 38,
GSM0808_CAUSE_INVALID_CELL = 39,
GSM0808_CAUSE_TRAFFIC_LOAD = 40,
GSM0808_CAUSE_PREEMPTION = 41,
GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE = 48,
GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH = 49,
GSM0808_CAUSE_SWITCH_CIRCUIT_POOL = 50,
GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE = 51,
GSM0808_CAUSE_LSA_NOT_ALLOWED = 52,
GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED = 64,
GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED = 80,
GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS = 81,
GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING = 82,
GSM0808_CAUSE_INCORRECT_VALUE = 83,
GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE = 84,
GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT = 85,
GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC = 96,
};
/* GSM 08.08 3.2.2.11 Channel Type */
enum gsm0808_chan_indicator {
GSM0808_CHAN_SPEECH = 1,
GSM0808_CHAN_DATA = 2,
GSM0808_CHAN_SIGN = 3,
};
enum gsm0808_chan_rate_type_data {
GSM0808_DATA_FULL_BM = 0x8,
GSM0808_DATA_HALF_LM = 0x9,
GSM0808_DATA_FULL_RPREF = 0xa,
GSM0808_DATA_HALF_PREF = 0xb,
GSM0808_DATA_FULL_PREF_NO_CHANGE = 0x1a,
GSM0808_DATA_HALF_PREF_NO_CHANGE = 0x1b,
GSM0808_DATA_MULTI_MASK = 0x20,
GSM0808_DATA_MULTI_MASK_NO_CHANGE = 0x30,
};
enum gsm0808_chan_rate_type_speech {
GSM0808_SPEECH_FULL_BM = 0x8,
GSM0808_SPEECH_HALF_LM = 0x9,
GSM0808_SPEECH_FULL_PREF= 0xa,
GSM0808_SPEECH_HALF_PREF= 0xb,
GSM0808_SPEECH_FULL_PREF_NO_CHANGE = 0x1a,
GSM0808_SPEECH_HALF_PREF_NO_CHANGE = 0x1b,
GSM0808_SPEECH_PERM = 0xf,
GSM0808_SPEECH_PERM_NO_CHANGE = 0x1f,
};
enum gsm0808_permitted_speech {
GSM0808_PERM_FR1 = 0x01,
GSM0808_PERM_FR2 = 0x11,
GSM0808_PERM_FR3 = 0x21,
GSM0808_PERM_HR1 = GSM0808_PERM_FR1 | 0x4,
GSM0808_PERM_HR2 = GSM0808_PERM_FR2 | 0x4,
GSM0808_PERM_HR3 = GSM0808_PERM_FR3 | 0x4,
};
int bssmap_rcvmsg_dt1(struct sccp_connection *conn, struct msgb *msg, unsigned int length);
int bssmap_rcvmsg_udt(struct gsm_network *net, struct msgb *msg, unsigned int length);
struct msgb *bssmap_create_layer3(struct msgb *msg);
struct msgb *bssmap_create_reset(void);
struct msgb *bssmap_create_clear_complete(void);
struct msgb *bssmap_create_cipher_complete(struct msgb *layer3);
struct msgb *bssmap_create_cipher_reject(u_int8_t cause);
struct msgb *bssmap_create_sapi_reject(u_int8_t link_id);
struct msgb *bssmap_create_assignment_completed(struct gsm_lchan *lchan, u_int8_t rr_cause);
struct msgb *bssmap_create_assignment_failure(u_int8_t cause, u_int8_t *rr_cause);
struct msgb *bssmap_create_classmark_update(const u_int8_t *classmark, u_int8_t length);
void gsm0808_send_assignment_failure(struct gsm_lchan *l, u_int8_t cause, u_int8_t *rr_value);
void gsm0808_send_assignment_compl(struct gsm_lchan *l, u_int8_t rr_value);
int dtap_rcvmsg(struct gsm_lchan *lchan, struct msgb *msg, unsigned int length);
struct msgb *dtap_create_msg(struct msgb *msg_l3, u_int8_t link_id);
void bsc_queue_connection_write(struct sccp_connection *conn, struct msgb *msg);
void bsc_free_queued(struct sccp_connection *conn);
void bsc_send_queued(struct sccp_connection *conn);
void bts_queue_send(struct msgb *msg, int link_id);
void bts_send_queued(struct bss_sccp_connection_data*);
void bts_free_queued(struct bss_sccp_connection_data*);
void bts_unblock_queue(struct bss_sccp_connection_data*);
const struct tlv_definition *gsm0808_att_tlvdef();
#endif

View File

@@ -23,6 +23,28 @@
#include "gsm_subscriber.h"
/*
* Refcounting for the lchan. If the refcount drops to zero
* the channel will send a RSL release request.
*/
#define use_lchan(lchan) \
do { lchan->use_count++; \
DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
lchan->nr, lchan->use_count); \
} while(0);
#define put_lchan(lchan, reason) \
do { lchan->use_count--; \
DEBUGP(DCC, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
lchan->nr, lchan->use_count); \
if (lchan->use_count <= 0) \
_lchan_release(lchan, reason); \
} while(0);
/* Special allocator for C0 of BTS */
struct gsm_bts_trx_ts *ts_c0_alloc(struct gsm_bts *bts,
enum gsm_phys_chan_config pchan);
@@ -46,8 +68,8 @@ struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type);
/* Free a logical channel (SDCCH, TCH, ...) */
void lchan_free(struct gsm_lchan *lchan);
/* Consider releasing the channel */
int lchan_auto_release(struct gsm_lchan *lchan);
/* internal.. do not use */
int _lchan_release(struct gsm_lchan *lchan, u_int8_t release_reason);
struct load_counter {
unsigned int total;

View File

@@ -28,6 +28,7 @@ enum {
DHO,
DDB,
DREF,
DNAT,
Debug_LastEntry,
};

View File

@@ -16,8 +16,9 @@ struct gsm_trans;
void gsm0408_allow_everyone(int allow);
int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id);
enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci);
enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci);
enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *bts, u_int8_t ra);
enum gsm_chreq_reason_t get_reason_by_chreq(u_int8_t ra, int neci);
void gsm_net_update_ctype(struct gsm_network *net);
int gsm48_tx_mm_info(struct gsm_lchan *lchan);
int gsm48_tx_mm_auth_req(struct gsm_lchan *lchan, u_int8_t *rand, int key_seq);

View File

@@ -79,31 +79,13 @@ typedef int gsm_cbfn(unsigned int hooknum,
struct msgb *msg,
void *data, void *param);
/*
* Use the channel. As side effect the lchannel recycle timer
* will be started.
*/
#define LCHAN_RELEASE_TIMEOUT 20, 0
#define use_lchan(lchan) \
do { lchan->use_count++; \
DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) increases usage to: %d\n", \
lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
lchan->nr, lchan->use_count); \
bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT); } while(0);
#define put_lchan(lchan) \
do { lchan->use_count--; \
DEBUGP(DREF, "lchan (bts=%d,trx=%d,ts=%d,ch=%d) decreases usage to: %d\n", \
lchan->ts->trx->bts->nr, lchan->ts->trx->nr, lchan->ts->nr, \
lchan->nr, lchan->use_count); \
} while(0);
/* communications link with a BTS */
struct gsm_bts_link {
struct gsm_bts *bts;
};
struct sccp_connection;
/* Real authentication information containing Ki */
enum gsm_auth_algo {
AUTH_ALGO_NONE,
@@ -131,6 +113,43 @@ struct gsm_subscriber;
struct gsm_mncc;
struct rtp_socket;
/* BSC/MSC data holding them together */
struct bss_sccp_connection_data {
struct gsm_lchan *lchan;
struct gsm_lchan *secondary_lchan;
struct sccp_connection *sccp;
int ciphering_handled : 1;
/* Timers... */
/* for assginment command */
struct timer_list T10;
/* for SCCP ... */
struct timer_list sccp_it;
/* audio handling */
int rtp_port;
/* Queue SCCP and GSM0408 messages */
int block_gsm;
struct llist_head gsm_queue;
unsigned int gsm_queue_size;
struct llist_head sccp_queue;
unsigned int sccp_queue_size;
/* Active connections */
struct llist_head active_connections;
};
#define GSM0808_T10_VALUE 6, 0
#define sccp_get_lchan(data_ctx) ((struct bss_sccp_connection_data *)data_ctx)->lchan
#define lchan_get_sccp(lchan) lchan->msc_data->sccp
struct bss_sccp_connection_data *bss_sccp_create_data();
void bss_sccp_free_data(struct bss_sccp_connection_data *);
/* Network Management State */
struct gsm_nm_state {
u_int8_t operational;
@@ -213,9 +232,6 @@ struct gsm_lchan {
/* To whom we are allocated at the moment */
struct gsm_subscriber *subscr;
/* Timer started to release the channel */
struct timer_list release_timer;
struct timer_list T3101;
/* Established data link layer services */
@@ -226,6 +242,12 @@ struct gsm_lchan {
*/
struct gsm_loc_updating_operation *loc_operation;
/*
* MSC handling...
*/
struct bss_sccp_connection_data *msc_data;
/* use count. how many users use this channel */
unsigned int use_count;
@@ -536,6 +558,14 @@ enum gsm_auth_policy {
#define GSM_T3101_DEFAULT 10
#define GSM_T3113_DEFAULT 60
/*
* internal data for audio management
*/
struct gsm_audio_support {
u_int8_t hr : 1,
ver : 7;
};
struct gsm_network {
/* global parameters */
u_int16_t country_code;
@@ -566,6 +596,11 @@ struct gsm_network {
struct gsmnet_stats stats;
struct gsm_audio_support **audio_support;
int audio_length;
int rtp_payload;
int rtp_base_port;
/* layer 4 */
int (*mncc_recv) (struct gsm_network *net, int msg_type, void *arg);
struct llist_head upqueue;
@@ -591,6 +626,18 @@ struct gsm_network {
struct {
enum rrlp_mode mode;
} rrlp;
enum gsm_chan_t ctype_by_chreq[16];
/* Use a TCH for handling requests of type paging any */
int pag_any_tch;
/* a hack for On Waves. It must be signed */
int32_t core_country_code;
int32_t core_network_code;
/* a simple token for this network... */
char *bsc_token;
};
#define SMS_HDR_SIZE 128

View File

@@ -81,6 +81,8 @@ struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net,
const char *ext);
struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net,
unsigned long long id);
struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net,
const char *imsi);
int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason);
void subscr_put_channel(struct gsm_lchan *lchan);
void subscr_get_channel(struct gsm_subscriber *subscr,

View File

@@ -29,7 +29,6 @@
#include <arpa/inet.h>
#define RTP_PORT_DEFAULT 4000
/**
* Calculate the RTP audio port for the given multiplex
* and the direction. This allows a semi static endpoint
@@ -77,14 +76,17 @@ struct mgcp_config;
typedef int (*mgcp_change)(struct mgcp_config *cfg, int endpoint, int state, int local_rtp);
typedef int (*mgcp_policy)(struct mgcp_config *cfg, int endpoint, int state, const char *transactio_id);
typedef int (*mgcp_reset)(struct mgcp_config *cfg);
struct mgcp_config {
/* common configuration */
int source_port;
char *local_ip;
char *source_addr;
unsigned int number_endpoints;
char *bts_ip;
char *call_agent_addr;
/* default endpoint data */
struct in_addr bts_in;
char *audio_name;
int audio_payload;
@@ -92,15 +94,21 @@ struct mgcp_config {
int early_bind;
int rtp_base_port;
/* only used in forward mode */
char *forward_ip;
int forward_port;
unsigned int last_call_id;
/* endpoint configuration */
unsigned int number_endpoints;
struct mgcp_endpoint *endpoints;
/* callback functionality */
mgcp_change change_cb;
mgcp_policy policy_cb;
mgcp_reset reset_cb;
void *data;
struct mgcp_endpoint *endpoints;
unsigned int last_call_id;
};
/* config management */
@@ -115,8 +123,15 @@ void mgcp_free_endp(struct mgcp_endpoint *endp);
* format helper functions
*/
struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg);
struct msgb *mgcp_create_rsip(void);
struct msgb *mgcp_create_response_with_data(int code, const char *msg, const char *trans, const char *data);
/* adc helper */
static inline int mgcp_timeslot_to_endpoint(int multiplex, int timeslot)
{
if (timeslot == 0)
timeslot = 1;
return timeslot + (31 * multiplex);
}
#endif

View File

@@ -61,4 +61,13 @@ struct mgcp_endpoint {
#define ENDPOINT_NUMBER(endp) abs(endp - endp->cfg->endpoints)
struct mgcp_msg_ptr {
unsigned int start;
unsigned int length;
};
int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
struct mgcp_msg_ptr *ptr, int size,
const char **transaction_id, struct mgcp_endpoint **endp);
#endif

View File

@@ -0,0 +1,6 @@
#ifndef OPENBSC_VTY_H
#define OPENBSC_VTY_H
void openbsc_vty_add_cmds(void);
#endif

View File

@@ -105,6 +105,11 @@ int sccp_connection_send_it(struct sccp_connection *connection);
int sccp_connection_close(struct sccp_connection *connection, int cause);
int sccp_connection_free(struct sccp_connection *connection);
/**
* internal..
*/
int sccp_connection_force_free(struct sccp_connection *conn);
/**
* Create a new socket. Set your callbacks and then call bind to open
* the connection.

View File

@@ -107,6 +107,8 @@ enum node_type {
TS_NODE,
SUBSCR_NODE,
MGCP_NODE,
NAT_NODE,
BSC_NODE,
};
/* Node which has some commands and prompt string and configuration

View File

@@ -3,7 +3,8 @@ AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS)
AM_LDFLAGS = $(LIBOSMOCORE_LIBS)
sbin_PROGRAMS = bsc_hack bs11_config ipaccess-find ipaccess-config \
isdnsync bsc_mgcp ipaccess-proxy
isdnsync bsc_mgcp ipaccess-proxy \
bsc_msc_ip bsc_nat
noinst_LIBRARIES = libbsc.a libmsc.a libvty.a
noinst_HEADERS = vty/cardshell.h
@@ -17,12 +18,12 @@ libbsc_a_SOURCES = abis_rsl.c abis_nm.c gsm_data.c gsm_04_08_utils.c \
input/misdn.c input/ipaccess.c \
talloc_ctx.c system_information.c rest_octets.c \
rtp_proxy.c bts_siemens_bs11.c bts_ipaccess_nanobts.c \
bts_unknown.c bsc_version.c
bts_unknown.c telnet_interface.c meas_rep.c bsc_version.c vty_interface_cmds.c
libmsc_a_SOURCES = gsm_subscriber.c db.c telnet_interface.c \
libmsc_a_SOURCES = gsm_subscriber.c db.c \
mncc.c gsm_04_08.c gsm_04_11.c transaction.c \
token_auth.c rrlp.c gsm_04_80.c ussd.c silent_call.c \
handover_logic.c handover_decision.c meas_rep.c
handover_logic.c handover_decision.c
libvty_a_SOURCES = vty/buffer.c vty/command.c vty/vector.c vty/vty.c
@@ -33,6 +34,10 @@ bsc_hack_LDADD = libmsc.a libbsc.a libmsc.a libvty.a -ldl -ldbi $(LIBCRYPT)
bs11_config_SOURCES = bs11_config.c abis_nm.c gsm_data.c debug.c \
rs232.c bts_siemens_bs11.c
bsc_msc_ip_SOURCES = bssap.c bsc_msc_ip.c bsc_init.c vty_interface.c vty_interface_bsc.c \
bsc_msc.c
bsc_msc_ip_LDADD = libbsc.a libvty.a libsccp.a
ipaccess_find_SOURCES = ipaccess/ipaccess-find.c
@@ -42,7 +47,13 @@ ipaccess_config_LDADD = libbsc.a libmsc.a libbsc.a libvty.a -ldl -ldbi $(LIBCRYP
isdnsync_SOURCES = isdnsync.c
bsc_mgcp_SOURCES = mgcp/mgcp_main.c mgcp/mgcp_protocol.c mgcp/mgcp_network.c mgcp/mgcp_vty.c \
debug.c telnet_interface.c
debug.c telnet_interface.c vty_interface_cmds.c
bsc_mgcp_LDADD = libvty.a
ipaccess_proxy_SOURCES = ipaccess/ipaccess-proxy.c debug.c
bsc_nat_SOURCES = nat/bsc_nat.c nat/bsc_filter.c nat/bsc_sccp.c \
nat/bsc_nat_utils.c nat/bsc_nat_vty.c nat/bsc_mgcp_utils.c \
mgcp/mgcp_protocol.c mgcp/mgcp_network.c mgcp/mgcp_vty.c \
bsc_msc.c bssap.c
bsc_nat_LDADD = libvty.a libbsc.a libsccp.a

View File

@@ -718,14 +718,15 @@ int rsl_establish_request(struct gsm_lchan *lchan, u_int8_t link_id)
RELEASE CONFIRM, which we in turn use to trigger RSL CHANNEL RELEASE,
which in turn is acknowledged by RSL CHANNEL RELEASE ACK, which calls
lchan_free() */
int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id)
int rsl_release_request(struct gsm_lchan *lchan, u_int8_t link_id, u_int8_t reason)
{
struct msgb *msg;
msg = rsl_rll_simple(RSL_MT_REL_REQ, lchan2chan_nr(lchan),
link_id, 0);
msgb_tv_put(msg, RSL_IE_RELEASE_MODE, 0); /* normal release */
/* 0 is normal release, 1 is local end */
msgb_tv_put(msg, RSL_IE_RELEASE_MODE, reason);
lchan->state = LCHAN_S_REL_REQ;
/* FIXME: start some timer in case we don't receive a REL ACK ? */
@@ -1103,8 +1104,8 @@ static int rsl_rx_chan_rqd(struct msgb *msg)
/* determine channel type (SDCCH/TCH_F/TCH_H) based on
* request reference RA */
lctype = get_ctype_by_chreq(bts, rqd_ref->ra, bts->network->neci);
chreq_reason = get_reason_by_chreq(bts, rqd_ref->ra, bts->network->neci);
lctype = get_ctype_by_chreq(bts->network, rqd_ref->ra);
chreq_reason = get_reason_by_chreq(rqd_ref->ra, bts->network->neci);
counter_inc(bts->network->stats.chreq.total);
@@ -1328,31 +1329,11 @@ static u_int8_t ipa_smod_s_for_lchan(struct gsm_lchan *lchan)
{
switch (lchan->tch_mode) {
case GSM48_CMODE_SPEECH_V1:
switch (lchan->type) {
case GSM_LCHAN_TCH_F:
return 0x00;
case GSM_LCHAN_TCH_H:
return 0x03;
default:
break;
}
return 0x00;
case GSM48_CMODE_SPEECH_EFR:
switch (lchan->type) {
case GSM_LCHAN_TCH_F:
return 0x01;
/* there's no half-rate EFR */
default:
break;
}
return 0x01;
case GSM48_CMODE_SPEECH_AMR:
switch (lchan->type) {
case GSM_LCHAN_TCH_F:
return 0x02;
case GSM_LCHAN_TCH_H:
return 0x05;
default:
break;
}
return 0x02;
default:
break;
}
@@ -1643,9 +1624,21 @@ static int abis_rsl_rx_ipacc(struct msgb *msg)
/* Entry-point where L2 RSL from BTS enters */
int abis_rsl_rcvmsg(struct msgb *msg)
{
struct abis_rsl_common_hdr *rslh = msgb_l2(msg) ;
struct abis_rsl_common_hdr *rslh;
int rc = 0;
if (!msg) {
DEBUGP(DRSL, "Empty RSL msg?..\n");
return -1;
}
if (msgb_l2len(msg) < sizeof(*rslh)) {
DEBUGP(DRSL, "Truncated RSL message with l2len: %u\n", msgb_l2len(msg));
return -1;
}
rslh = msgb_l2(msg);
switch (rslh->msg_discr & 0xfe) {
case ABIS_RSL_MDISC_RLL:
rc = abis_rsl_rx_rll(msg);

View File

@@ -870,3 +870,8 @@ int main(int argc, char **argv)
exit(0);
}
/* dummy to be able to compile */
void gsm_net_update_ctype(struct gsm_network *net)
{
}

24
openbsc/src/bsc-nat.cfg Normal file
View File

@@ -0,0 +1,24 @@
!
! BSC NAT configuration hand edited
! !
password foo
!
line vty
no login
!
nat
bsc 0
token zecke
location_area_code 3
bsc 1
token roch
location_area_code 4
mgcp
local ip 10.0.0.23
bts ip 0.0.0.0
bind ip 127.0.0.1
bind port 2427
bind early 1
rtp base 4000
number endpoints 31
call agent ip 127.0.0.1

View File

@@ -426,6 +426,7 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
case NM_OC_BTS:
bts = obj;
if (new_state->availability == NM_AVSTATE_DEPENDENCY) {
printf("STARTING BTS...\n");
patch_nm_tables(bts);
abis_nm_set_bts_attr(bts, nanobts_attr_bts,
sizeof(nanobts_attr_bts));
@@ -441,6 +442,7 @@ int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
trx = ts->trx;
if (new_state->operational == 1 &&
new_state->availability == NM_AVSTATE_DEPENDENCY) {
printf("STARTING OC Channel...\n");
patch_nm_tables(trx->bts);
enum abis_nm_chan_comb ccomb =
abis_nm_chcomb4pchan(ts->pchan);

214
openbsc/src/bsc_msc.c Normal file
View File

@@ -0,0 +1,214 @@
/* Routines to talk to the MSC using the IPA Protocol */
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <openbsc/bsc_msc.h>
#include <openbsc/debug.h>
#include <osmocore/write_queue.h>
#include <osmocore/talloc.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static void connection_loss(struct bsc_msc_connection *con)
{
struct bsc_fd *fd;
fd = &con->write_queue.bfd;
close(fd->fd);
fd->fd = -1;
fd->cb = write_queue_bfd_cb;
fd->when = 0;
con->is_connected = 0;
con->connection_loss(con);
}
/* called in the case of a non blocking connect */
static int msc_connection_connect(struct bsc_fd *fd, unsigned int what)
{
int rc;
int val;
struct bsc_msc_connection *con;
struct write_queue *queue;
socklen_t len = sizeof(val);
if ((what & BSC_FD_WRITE) == 0) {
LOGP(DMSC, LOGL_ERROR, "Callback but not readable.\n");
return -1;
}
queue = container_of(fd, struct write_queue, bfd);
con = container_of(queue, struct bsc_msc_connection, write_queue);
/* check the socket state */
rc = getsockopt(fd->fd, SOL_SOCKET, SO_ERROR, &val, &len);
if (rc != 0) {
LOGP(DMSC, LOGL_ERROR, "getsockopt for the MSC socket failed.\n");
goto error;
}
if (val != 0) {
LOGP(DMSC, LOGL_ERROR, "Not connected to the MSC: %d\n", val);
goto error;
}
/* go to full operation */
fd->cb = write_queue_bfd_cb;
fd->when = BSC_FD_READ;
con->is_connected = 1;
LOGP(DMSC, LOGL_NOTICE, "(Re)Connected to the MSC.\n");
if (con->connected)
con->connected(con);
return 0;
error:
bsc_unregister_fd(fd);
connection_loss(con);
return -1;
}
static void setnonblocking(struct bsc_fd *fd)
{
int flags;
flags = fcntl(fd->fd, F_GETFL);
if (flags < 0) {
perror("fcntl get failed");
close(fd->fd);
fd->fd = -1;
return;
}
flags |= O_NONBLOCK;
flags = fcntl(fd->fd, F_SETFL, flags);
if (flags < 0) {
perror("fcntl get failed");
close(fd->fd);
fd->fd = -1;
return;
}
}
int bsc_msc_connect(struct bsc_msc_connection *con)
{
struct bsc_fd *fd;
struct sockaddr_in sin;
int on = 1, ret;
LOGP(DMSC, LOGL_NOTICE, "Attempting to connect MSC at %s:%d\n", con->ip, con->port);
con->is_connected = 0;
fd = &con->write_queue.bfd;
fd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
fd->data = NULL;
fd->priv_nr = 1;
if (fd->fd < 0) {
perror("Creating TCP socket failed");
return fd->fd;
}
/* make it non blocking */
setnonblocking(fd);
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(con->port);
inet_aton(con->ip, &sin.sin_addr);
setsockopt(fd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
ret = connect(fd->fd, (struct sockaddr *) &sin, sizeof(sin));
if (ret == -1 && errno == EINPROGRESS) {
LOGP(DMSC, LOGL_ERROR, "MSC Connection in progress\n");
fd->when = BSC_FD_WRITE;
fd->cb = msc_connection_connect;
} else if (ret < 0) {
perror("Connection failed");
connection_loss(con);
return ret;
} else {
fd->when = BSC_FD_READ;
fd->cb = write_queue_bfd_cb;
con->is_connected = 1;
if (con->connected)
con->connected(con);
}
ret = bsc_register_fd(fd);
if (ret < 0) {
perror("Registering the fd failed");
close(fd->fd);
return ret;
}
return ret;
}
struct bsc_msc_connection *bsc_msc_create(const char *ip, int port)
{
struct bsc_msc_connection *con;
con = talloc_zero(NULL, struct bsc_msc_connection);
if (!con) {
LOGP(DMSC, LOGL_FATAL, "Failed to create the MSC connection.\n");
return NULL;
}
con->ip = ip;
con->port = port;
write_queue_init(&con->write_queue, 100);
return con;
}
void bsc_msc_lost(struct bsc_msc_connection *con)
{
write_queue_clear(&con->write_queue);
bsc_unregister_fd(&con->write_queue.bfd);
connection_loss(con);
}
static void reconnect_msc(void *_msc)
{
struct bsc_msc_connection *con = _msc;
LOGP(DMSC, LOGL_NOTICE, "Attempting to reconnect to the MSC.\n");
bsc_msc_connect(con);
}
void bsc_msc_schedule_connect(struct bsc_msc_connection *con)
{
LOGP(DMSC, LOGL_NOTICE, "Attempting to reconnect to the MSC.\n");
con->reconnect_timer.cb = reconnect_msc;
con->reconnect_timer.data = con;
bsc_schedule_timer(&con->reconnect_timer, 5, 0);
}

1071
openbsc/src/bsc_msc_ip.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -52,7 +52,7 @@ static LLIST_HEAD(bsc_rll_reqs);
static void complete_rllr(struct bsc_rll_req *rllr, enum bsc_rllr_ind type)
{
llist_del(&rllr->list);
put_lchan(rllr->lchan);
put_lchan(rllr->lchan, 0);
rllr->cb(rllr->lchan, rllr->link_id, rllr->data, type);
talloc_free(rllr);
}

1312
openbsc/src/bssap.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -33,8 +33,6 @@
#include <openbsc/debug.h>
#include <openbsc/signal.h>
static void auto_release_channel(void *_lchan);
static int ts_is_usable(struct gsm_bts_trx_ts *ts)
{
/* FIXME: How does this behave for BS-11 ? */
@@ -260,10 +258,9 @@ struct gsm_lchan *lchan_alloc(struct gsm_bts *bts, enum gsm_chan_t type)
/* clear multi rate config */
memset(&lchan->mr_conf, 0, sizeof(lchan->mr_conf));
/* Configure the time and start it so it will be closed */
lchan->release_timer.cb = auto_release_channel;
lchan->release_timer.data = lchan;
bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT);
/* clear any msc reference */
lchan->msc_data = NULL;
}
return lchan;
@@ -286,8 +283,6 @@ void lchan_free(struct gsm_lchan *lchan)
lchan->use_count = 0;
}
/* stop the timer */
bsc_del_timer(&lchan->release_timer);
bsc_del_timer(&lchan->T3101);
/* clear cached measuement reports */
@@ -298,7 +293,6 @@ void lchan_free(struct gsm_lchan *lchan)
}
for (i = 0; i < ARRAY_SIZE(lchan->neigh_meas); i++)
lchan->neigh_meas[i].arfcn = 0;
lchan->silent_call = 0;
/* FIXME: ts_free() the timeslot, if we're the last logical
@@ -306,15 +300,18 @@ void lchan_free(struct gsm_lchan *lchan)
}
/* Consider releasing the channel now */
int lchan_auto_release(struct gsm_lchan *lchan)
int _lchan_release(struct gsm_lchan *lchan, u_int8_t release_reason)
{
if (lchan->use_count > 0) {
DEBUGP(DRLL, "BUG: _lchan_release called without zero use_count.\n");
return 0;
}
/* Assume we have GSM04.08 running and send a release */
if (lchan->subscr) {
++lchan->use_count;
gsm48_send_rr_release(lchan);
--lchan->use_count;
}
/* spoofed? message */
@@ -323,19 +320,10 @@ int lchan_auto_release(struct gsm_lchan *lchan)
lchan->use_count);
DEBUGP(DRLL, "%s Recycling Channel\n", gsm_lchan_name(lchan));
rsl_release_request(lchan, 0);
rsl_release_request(lchan, 0, release_reason);
return 1;
}
/* Auto release the channel when the use count is zero */
static void auto_release_channel(void *_lchan)
{
struct gsm_lchan *lchan = _lchan;
if (!lchan_auto_release(lchan))
bsc_schedule_timer(&lchan->release_timer, LCHAN_RELEASE_TIMEOUT);
}
struct gsm_lchan* lchan_find(struct gsm_bts *bts, struct gsm_subscriber *subscr) {
struct gsm_bts_trx *trx;
int ts_no, lchan_no;

View File

@@ -55,6 +55,7 @@ static struct debug_category default_categories[Debug_LastEntry] = {
[DHO] = { .enabled = 1, .loglevel = LOGL_NOTICE },
[DDB] = { .enabled = 1, .loglevel = LOGL_NOTICE },
[DREF] = { .enabled = 0, .loglevel = LOGL_NOTICE },
[DNAT] = { .enabled = 1, .loglevel = LOGL_NOTICE },
};
struct debug_info {
@@ -97,6 +98,7 @@ static const struct debug_info debug_info[] = {
DEBUG_CATEGORY(DMSC, "DMSC", "", "")
DEBUG_CATEGORY(DMGCP, "DMGCP", "", "")
DEBUG_CATEGORY(DHO, "DHO", "", "")
DEBUG_CATEGORY(DNAT, "DNAT", "", "")
DEBUG_CATEGORY(DDB, "DDB", "", "")
DEBUG_CATEGORY(DREF, "DREF", "", "")
};

View File

@@ -104,7 +104,7 @@ static void release_loc_updating_req(struct gsm_lchan *lchan)
bsc_del_timer(&lchan->loc_operation->updating_timer);
talloc_free(lchan->loc_operation);
lchan->loc_operation = 0;
put_lchan(lchan);
put_lchan(lchan, 0);
}
static void allocate_loc_updating_req(struct gsm_lchan *lchan)
@@ -122,7 +122,6 @@ static int gsm0408_authorize(struct gsm_lchan *lchan, struct msgb *msg)
int rc;
db_subscriber_alloc_tmsi(lchan->subscr);
release_loc_updating_req(lchan);
rc = gsm0408_loc_upd_acc(msg->lchan, lchan->subscr->tmsi);
if (lchan->ts->trx->bts->network->send_mm_info) {
/* send MM INFO with network name */
@@ -134,8 +133,7 @@ static int gsm0408_authorize(struct gsm_lchan *lchan, struct msgb *msg)
* trigger further action like SMS delivery */
subscr_update(lchan->subscr, msg->trx->bts,
GSM_SUBSCRIBER_UPDATE_ATTACHED);
/* try to close channel ASAP */
lchan_auto_release(lchan);
release_loc_updating_req(lchan);
return rc;
}
@@ -291,9 +289,8 @@ static void loc_upd_rej_cb(void *data)
struct gsm_lchan *lchan = data;
struct gsm_bts *bts = lchan->ts->trx->bts;
release_loc_updating_req(lchan);
gsm0408_loc_upd_rej(lchan, bts->network->reject_cause);
lchan_auto_release(lchan);
release_loc_updating_req(lchan);
}
static void schedule_reject(struct gsm_lchan *lchan)
@@ -713,8 +710,6 @@ static int gsm48_rx_mm_imsi_detach_ind(struct msgb *msg)
* imagine an IMSI DETACH happening during an active call! */
/* subscriber is detached: should we release lchan? */
lchan_auto_release(msg->lchan);
return 0;
}
@@ -2061,7 +2056,6 @@ static int gsm48_cc_rx_release_compl(struct gsm_trans *trans, struct msgb *msg)
MNCC_REL_CNF, &rel);
/* FIXME: in case of multiple calls, we can't simply
* hang up here ! */
lchan_auto_release(msg->lchan);
break;
default:
rc = mncc_recvmsg(trans->subscr->net, trans,

View File

@@ -164,13 +164,46 @@ static const enum gsm_chreq_reason_t reason_by_chreq[] = {
[CHREQ_T_RESERVED_IGNORE] = GSM_CHREQ_REASON_OTHER,
};
enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci)
/* verify that the two tables match */
static_assert(sizeof(ctype_by_chreq) ==
sizeof(((struct gsm_network *) NULL)->ctype_by_chreq), assert_size);
/*
* Update channel types for request based on policy. E.g. in the
* case of a TCH/H network/bsc use TCH/H for the emergency calls,
* for early assignment assign a SDCCH and some other options.
*/
void gsm_net_update_ctype(struct gsm_network *network)
{
/* copy over the data */
memcpy(network->ctype_by_chreq, ctype_by_chreq, sizeof(ctype_by_chreq));
/*
* Use TCH/H for emergency calls when this cell allows TCH/H. Maybe it
* is better to iterate over the BTS/TRX and check if no TCH/F is available
* and then set it to TCH/H.
*/
if (network->neci)
network->ctype_by_chreq[CHREQ_T_EMERG_CALL] = GSM_LCHAN_TCH_H;
if (network->pag_any_tch) {
if (network->neci) {
network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_H;
network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_H;
} else {
network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI0] = GSM_LCHAN_TCH_F;
network->ctype_by_chreq[CHREQ_T_PAG_R_ANY_NECI1] = GSM_LCHAN_TCH_F;
}
}
}
enum gsm_chan_t get_ctype_by_chreq(struct gsm_network *network, u_int8_t ra)
{
int i;
int length;
const struct chreq *chreq;
if (neci) {
if (network->neci) {
chreq = chreq_type_neci1;
length = ARRAY_SIZE(chreq_type_neci1);
} else {
@@ -182,13 +215,13 @@ enum gsm_chan_t get_ctype_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci)
for (i = 0; i < length; i++) {
const struct chreq *chr = &chreq[i];
if ((ra & chr->mask) == chr->val)
return ctype_by_chreq[chr->type];
return network->ctype_by_chreq[chr->type];
}
LOGP(DRR, LOGL_ERROR, "Unknown CHANNEL REQUEST RQD 0x%02x\n", ra);
return GSM_LCHAN_SDCCH;
}
enum gsm_chreq_reason_t get_reason_by_chreq(struct gsm_bts *bts, u_int8_t ra, int neci)
enum gsm_chreq_reason_t get_reason_by_chreq(u_int8_t ra, int neci)
{
int i;
int length;

View File

@@ -762,7 +762,7 @@ static int gsm411_rx_rp_ack(struct msgb *msg, struct gsm_trans *trans,
/* release channel if done */
if (!sms)
rsl_release_request(msg->lchan, trans->sms.link_id);
rsl_release_request(msg->lchan, trans->sms.link_id, 0);
return 0;
}
@@ -837,7 +837,7 @@ static int gsm411_rx_rp_smma(struct msgb *msg, struct gsm_trans *trans,
if (sms)
gsm411_send_sms_lchan(msg->lchan, sms);
else
rsl_release_request(msg->lchan, trans->sms.link_id);
rsl_release_request(msg->lchan, trans->sms.link_id, 0);
return rc;
}

View File

@@ -283,6 +283,12 @@ struct gsm_network *gsm_network_init(u_int16_t country_code, u_int16_t network_c
net->mncc_recv = mncc_recv;
gsm_net_update_ctype(net);
net->core_country_code = -1;
net->core_network_code = -1;
net->rtp_base_port = 4000;
return net;
}

View File

@@ -31,6 +31,7 @@
#include <openbsc/gsm_subscriber.h>
#include <openbsc/paging.h>
#include <openbsc/debug.h>
#include <openbsc/chan_alloc.h>
LLIST_HEAD(active_subscribers);
void *tall_subscr_ctx;
@@ -88,6 +89,7 @@ static int subscr_paging_cb(unsigned int hooknum, unsigned int event,
request->cbfn(hooknum, event, msg, data, request->param);
subscr->in_callback = 0;
subscr_put(request->subscr);
talloc_free(request);
return 0;
}
@@ -165,7 +167,7 @@ void subscr_get_channel(struct gsm_subscriber *subscr,
}
memset(request, 0, sizeof(*request));
request->subscr = subscr;
request->subscr = subscr_get(subscr);
request->channel_type = type;
request->cbfn = cbfn;
request->param = param;
@@ -205,9 +207,28 @@ void subscr_put_channel(struct gsm_lchan *lchan)
* will listen to the paging requests before we timeout
*/
put_lchan(lchan);
put_lchan(lchan, 0);
if (lchan->subscr && !llist_empty(&lchan->subscr->requests))
subscr_send_paging_request(lchan->subscr);
}
struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net,
const char *imsi)
{
struct gsm_subscriber *subscr;
llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) {
if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net)
return subscr_get(subscr);
}
subscr = subscr_alloc();
if (!subscr)
return NULL;
strcpy(subscr->imsi, imsi);
subscr->net = net;
return subscr;
}

View File

@@ -230,7 +230,6 @@ static int ho_gsm48_ho_compl(struct gsm_lchan *new_lchan)
trans_lchan_change(ho->old_lchan, new_lchan);
ho->old_lchan->state = LCHAN_S_INACTIVE;
lchan_auto_release(ho->old_lchan);
/* do something to re-route the actual speech frames ! */
@@ -256,7 +255,7 @@ static int ho_gsm48_ho_fail(struct gsm_lchan *old_lchan)
bsc_del_timer(&ho->T3103);
llist_del(&ho->list);
put_lchan(ho->new_lchan);
put_lchan(ho->new_lchan, 0);
talloc_free(ho);
return 0;

View File

@@ -57,7 +57,7 @@ struct ia_e1_handle {
static struct ia_e1_handle *e1h;
#define TS1_ALLOC_SIZE 300
#define TS1_ALLOC_SIZE 900
static const u_int8_t pong[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG };
static const u_int8_t id_ack[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK };

View File

@@ -38,7 +38,11 @@
#include <openbsc/gsm_data.h>
#include <osmocore/select.h>
#include <openbsc/mgcp.h>
#include <openbsc/mgcp_internal.h>
#include <openbsc/telnet_interface.h>
#include <openbsc/vty.h>
#include <vty/command.h>
#include "../../bscconfig.h"
@@ -51,8 +55,9 @@ void subscr_put() { abort(); }
#warning "Make use of the rtp proxy code"
static struct bsc_fd bfd;
static int first_request = 1;
static struct mgcp_config *cfg;
static int reset_endpoints = 0;
const char *openbsc_version = "OpenBSC MGCP " PACKAGE_VERSION;
const char *openbsc_copyright =
"Copyright (C) 2009-2010 Holger Freyther and On-Waves\n"
@@ -74,10 +79,10 @@ static void print_help()
printf(" -c --config-file filename The config file to use.\n");
}
static void print_version()
static void print_mgcp_version()
{
printf("%s\n\n", openbsc_version);
printf(openbsc_copyright);
printf("%s", openbsc_copyright);
}
static void handle_options(int argc, char** argv)
@@ -105,7 +110,7 @@ static void handle_options(int argc, char** argv)
config_file = talloc_strdup(tall_bsc_ctx, optarg);
break;
case 'V':
print_version();
print_mgcp_version();
exit(0);
break;
default:
@@ -115,12 +120,21 @@ static void handle_options(int argc, char** argv)
}
}
/* simply remember this */
static int mgcp_rsip_cb(struct mgcp_config *cfg)
{
reset_endpoints = 1;
return 0;
}
static int read_call_agent(struct bsc_fd *fd, unsigned int what)
{
struct sockaddr_in addr;
socklen_t slen = sizeof(addr);
struct msgb *msg;
struct msgb *resp;
int i;
msg = (struct msgb *) fd->data;
@@ -136,18 +150,6 @@ static int read_call_agent(struct bsc_fd *fd, unsigned int what)
return -1;
}
if (first_request) {
first_request = 0;
resp = mgcp_create_rsip();
if (resp) {
sendto(bfd.fd, resp->l2h, msgb_l2len(resp), 0,
(struct sockaddr *) &addr, sizeof(addr));
msgb_free(resp);
}
return 0;
}
/* handle message now */
msg->l2h = msgb_put(msg, rc);
resp = mgcp_handle_message(cfg, msg);
@@ -157,6 +159,16 @@ static int read_call_agent(struct bsc_fd *fd, unsigned int what)
sendto(bfd.fd, resp->l2h, msgb_l2len(resp), 0, (struct sockaddr *) &addr, sizeof(addr));
msgb_free(resp);
}
if (reset_endpoints) {
LOGP(DMGCP, LOGL_NOTICE, "Asked to reset endpoints.\n");
reset_endpoints = 0;
/* is checking in_addr.s_addr == INADDR_LOOPBACK making it more secure? */
for (i = 1; i < cfg->number_endpoints; ++i)
mgcp_free_endp(&cfg->endpoints[i]);
}
return 0;
}
@@ -186,6 +198,8 @@ int main(int argc, char** argv)
if (rc < 0)
return rc;
/* set some callbacks */
cfg->reset_cb = mgcp_rsip_cb;
/* we need to bind a socket */
if (rc == 0) {
@@ -217,11 +231,11 @@ int main(int argc, char** argv)
if (bsc_register_fd(&bfd) != 0) {
DEBUGP(DMGCP, "Failed to register the fd\n");
LOGP(DMGCP, LOGL_FATAL, "Failed to register the fd\n");
return -1;
}
DEBUGP(DMGCP, "Configured for MGCP.\n");
LOGP(DMGCP, LOGL_NOTICE, "Configured for MGCP.\n");
}
/* initialisation */
@@ -235,3 +249,15 @@ int main(int argc, char** argv)
return 0;
}
struct gsm_network;
int bsc_vty_init(struct gsm_network *dummy)
{
cmd_init(1);
vty_init();
openbsc_vty_add_cmds();
mgcp_vty_init();
return 0;
}

View File

@@ -90,6 +90,9 @@ static void patch_payload(int payload, char *data, int len)
if (len < sizeof(*rtp_hdr))
return;
if (payload < 0)
return;
rtp_hdr = (struct rtp_hdr *) data;
rtp_hdr->payload_type = payload;
}
@@ -126,7 +129,7 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
/* do not forward aynthing... maybe there is a packet from the bts */
if (endp->ci == CI_UNUSED) {
LOGP(DMGCP, LOGL_ERROR, "Unknown message on endpoint: 0x%x\n", ENDPOINT_NUMBER(endp));
LOGP(DMGCP, LOGL_DEBUG, "Unknown message on endpoint: 0x%x\n", ENDPOINT_NUMBER(endp));
return -1;
}
@@ -146,7 +149,9 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
/* We have no idea who called us, maybe it is the BTS. */
if (dest == DEST_NETWORK && (endp->bts_rtp == 0 || cfg->forward_ip)) {
/* it was the BTS... */
if (!cfg->bts_ip || memcmp(&addr.sin_addr, &cfg->bts_in, sizeof(cfg->bts_in)) == 0) {
if (!cfg->bts_ip
|| memcmp(&addr.sin_addr, &cfg->bts_in, sizeof(cfg->bts_in)) == 0
|| memcmp(&addr.sin_addr, &endp->bts, sizeof(endp->bts)) == 0) {
if (fd == &endp->local_rtp) {
endp->bts_rtp = addr.sin_port;
} else {

View File

@@ -80,11 +80,6 @@ enum mgcp_connection_mode {
}
struct mgcp_msg_ptr {
unsigned int start;
unsigned int length;
};
struct mgcp_request {
char *name;
struct msgb *(*handle_request) (struct mgcp_config *cfg, struct msgb *msg);
@@ -98,6 +93,7 @@ static struct msgb *handle_audit_endpoint(struct mgcp_config *cfg, struct msgb *
static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg);
static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg);
static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg);
static struct msgb *handle_rsip(struct mgcp_config *cfg, struct msgb *msg);
static int generate_call_id(struct mgcp_config *cfg)
{
@@ -119,12 +115,6 @@ static int generate_call_id(struct mgcp_config *cfg)
return cfg->last_call_id;
}
/* FIXIME/TODO: need to have a list of pending transactions and check that */
static unsigned int generate_transaction_id()
{
return abs(rand());
}
/*
* array of function pointers for handling various
* messages. In the future this might be binary sorted
@@ -135,6 +125,9 @@ static const struct mgcp_request mgcp_requests [] = {
MGCP_REQUEST("CRCX", handle_create_con, "CreateConnection")
MGCP_REQUEST("DLCX", handle_delete_con, "DeleteConnection")
MGCP_REQUEST("MDCX", handle_modify_con, "ModifiyConnection")
/* SPEC extension */
MGCP_REQUEST("RSIP", handle_rsip, "ReSetInProgress")
};
static struct msgb *mgcp_msgb_alloc(void)
@@ -194,23 +187,6 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
return mgcp_create_response_with_data(200, msg, trans_id, sdp_record);
}
/* send a static record */
struct msgb *mgcp_create_rsip(void)
{
struct msgb *msg;
int len;
msg = mgcp_msgb_alloc();
if (!msg)
return NULL;
len = snprintf((char *) msg->data, 2048,
"RSIP %u *@mgw MGCP 1.0\n"
"RM: restart\n", generate_transaction_id());
msg->l2h = msgb_put(msg, len);
return msg;
}
/*
* handle incoming messages:
* - this can be a command (four letters, space, transaction id)
@@ -221,25 +197,25 @@ struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg)
int code;
struct msgb *resp = NULL;
if (msg->len < 4) {
if (msgb_l2len(msg) < 4) {
LOGP(DMGCP, LOGL_ERROR, "mgs too short: %d\n", msg->len);
return NULL;
}
/* attempt to treat it as a response */
if (sscanf((const char *)&msg->data[0], "%3d %*s", &code) == 1) {
if (sscanf((const char *)&msg->l2h[0], "%3d %*s", &code) == 1) {
LOGP(DMGCP, LOGL_DEBUG, "Response: Code: %d\n", code);
} else {
int i, handled = 0;
msg->l3h = &msg->l2h[4];
for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i)
if (strncmp(mgcp_requests[i].name, (const char *) &msg->data[0], 4) == 0) {
if (strncmp(mgcp_requests[i].name, (const char *) &msg->l2h[0], 4) == 0) {
handled = 1;
resp = mgcp_requests[i].handle_request(cfg, msg);
break;
}
if (!handled) {
LOGP(DMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n", &msg->data[0]);
LOGP(DMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n", &msg->l2h[0]);
}
}
@@ -296,9 +272,9 @@ static struct mgcp_endpoint *find_endpoint(struct mgcp_config *cfg, const char *
return &cfg->endpoints[gw];
}
static int analyze_header(struct mgcp_config *cfg, struct msgb *msg,
struct mgcp_msg_ptr *ptr, int size,
const char **transaction_id, struct mgcp_endpoint **endp)
int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg,
struct mgcp_msg_ptr *ptr, int size,
const char **transaction_id, struct mgcp_endpoint **endp)
{
int found;
@@ -334,8 +310,11 @@ static int analyze_header(struct mgcp_config *cfg, struct msgb *msg,
}
*transaction_id = (const char *)&msg->l3h[ptr[0].start];
*endp = find_endpoint(cfg, (const char *)&msg->l3h[ptr[1].start]);
return *endp == NULL;
if (endp) {
*endp = find_endpoint(cfg, (const char *)&msg->l3h[ptr[1].start]);
return *endp == NULL;
}
return 0;
}
static int verify_call_id(const struct mgcp_endpoint *endp,
@@ -369,7 +348,7 @@ static struct msgb *handle_audit_endpoint(struct mgcp_config *cfg, struct msgb *
const char *trans_id;
struct mgcp_endpoint *endp;
found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
response = 500;
else
@@ -402,7 +381,7 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg)
int error_code = 500;
int port;
found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
return create_response(500, "CRCX", trans_id);
@@ -501,7 +480,7 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
struct mgcp_endpoint *endp;
int error_code = 500;
found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
return create_response(error_code, "MDCX", trans_id);
@@ -614,7 +593,7 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
struct mgcp_endpoint *endp;
int error_code = 500;
found = analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
found = mgcp_analyze_header(cfg, msg, data_ptrs, ARRAY_SIZE(data_ptrs), &trans_id, &endp);
if (found != 0)
return create_response(error_code, "DLCX", trans_id);
@@ -678,6 +657,13 @@ error3:
return create_response(error_code, "DLCX", trans_id);
}
static struct msgb *handle_rsip(struct mgcp_config *cfg, struct msgb *msg)
{
if (cfg->reset_cb)
cfg->reset_cb(cfg);
return NULL;
}
struct mgcp_config *mgcp_config_alloc(void)
{
struct mgcp_config *cfg;
@@ -722,7 +708,7 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg)
void mgcp_free_endp(struct mgcp_endpoint *endp)
{
LOGP(DMGCP, LOGL_NOTICE, "Deleting endpoint on: 0x%x\n", ENDPOINT_NUMBER(endp));
LOGP(DMGCP, LOGL_DEBUG, "Deleting endpoint on: 0x%x\n", ENDPOINT_NUMBER(endp));
endp->ci= CI_UNUSED;
if (endp->callid) {
@@ -732,7 +718,7 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
if (endp->local_options) {
talloc_free(endp->local_options);
endp->callid = NULL;
endp->local_options = NULL;
}
if (!endp->cfg->early_bind) {
@@ -742,4 +728,6 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
endp->net_rtp = endp->net_rtcp = endp->bts_rtp = endp->bts_rtcp = 0;
endp->net_payload_type = endp->bts_payload_type = -1;
memset(&endp->remote, 0, sizeof(endp->remote));
memset(&endp->bts, 0, sizeof(endp->bts));
}

View File

@@ -63,6 +63,8 @@ static int config_write_mgcp(struct vty *vty)
vty_out(vty, " forward audio ip %s%s", g_cfg->forward_ip, VTY_NEWLINE);
if (g_cfg->forward_port != 0)
vty_out(vty, " forward audio port %d%s", g_cfg->forward_port, VTY_NEWLINE);
if (g_cfg->call_agent_addr)
vty_out(vty, " call agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -75,10 +77,11 @@ DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp",
vty_out(vty, "MGCP is up and running with %u endpoints:%s", g_cfg->number_endpoints - 1, VTY_NEWLINE);
for (i = 1; i < g_cfg->number_endpoints; ++i) {
struct mgcp_endpoint *endp = &g_cfg->endpoints[i];
vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u%s",
vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s%s",
i, endp->ci,
ntohs(endp->net_rtp), ntohs(endp->net_rtcp),
ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp), VTY_NEWLINE);
ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp),
inet_ntoa(endp->bts), VTY_NEWLINE);
}
return CMD_SUCCESS;
@@ -237,6 +240,17 @@ DEFUN(cfg_mgcp_forward_port,
return CMD_SUCCESS;
}
DEFUN(cfg_mgcp_agent_addr,
cfg_mgcp_agent_addr_cmd,
"call agent ip IP",
"Set the address of the call agent.")
{
if (g_cfg->call_agent_addr)
talloc_free(g_cfg->call_agent_addr);
g_cfg->call_agent_addr = talloc_strdup(g_cfg, argv[0]);
return CMD_SUCCESS;
}
int mgcp_vty_init(void)
{
install_element(VIEW_NODE, &show_mgcp_cmd);
@@ -256,6 +270,7 @@ int mgcp_vty_init(void)
install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd);
install_element(MGCP_NODE, &cfg_mgcp_forward_ip_cmd);
install_element(MGCP_NODE, &cfg_mgcp_forward_port_cmd);
install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd);
return 0;
}
@@ -274,6 +289,11 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
if (!g_cfg->bts_ip)
fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n");
if (!g_cfg->source_addr) {
fprintf(stderr, "You need to specify a bind address.\n");
return -1;
}
if (mgcp_endpoints_allocate(g_cfg) != 0) {
fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n", g_cfg->number_endpoints);
return -1;
@@ -327,13 +347,3 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
return !!g_cfg->forward_ip;
}
struct gsm_network;
int bsc_vty_init(struct gsm_network *dummy)
{
cmd_init(1);
vty_init();
mgcp_vty_init();
return 0;
}

View File

@@ -0,0 +1,216 @@
/* BSC Multiplexer/NAT */
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <openbsc/bsc_nat.h>
#include <openbsc/bssap.h>
#include <openbsc/ipaccess.h>
#include <openbsc/debug.h>
#include <osmocore/talloc.h>
#include <sccp/sccp.h>
/*
* The idea is to have a simple struct describing a IPA packet with
* SCCP SSN and the GSM 08.08 payload and decide. We will both have
* a white and a blacklist of packets we want to handle.
*
* TODO: Implement a "NOT" in the filter language.
*/
#define ALLOW_ANY -1
#define FILTER_TO_BSC 1
#define FILTER_TO_MSC 2
#define FILTER_TO_BOTH 3
struct bsc_pkt_filter {
int ipa_proto;
int dest_ssn;
int bssap;
int gsm;
int filter_dir;
};
static struct bsc_pkt_filter black_list[] = {
/* filter reset messages to the MSC */
{ IPAC_PROTO_SCCP, SCCP_SSN_BSSAP, 0, BSS_MAP_MSG_RESET, FILTER_TO_MSC },
/* filter reset ack messages to the BSC */
{ IPAC_PROTO_SCCP, SCCP_SSN_BSSAP, 0, BSS_MAP_MSG_RESET_ACKNOWLEDGE, FILTER_TO_BSC },
/* filter ip access */
{ IPAC_PROTO_IPACCESS, ALLOW_ANY, ALLOW_ANY, ALLOW_ANY, FILTER_TO_MSC },
};
static struct bsc_pkt_filter white_list[] = {
/* allow IPAC_PROTO_SCCP messages to both sides */
{ IPAC_PROTO_SCCP, ALLOW_ANY, ALLOW_ANY, ALLOW_ANY, FILTER_TO_BOTH },
/* allow MGCP messages to both sides */
{ NAT_IPAC_PROTO_MGCP, ALLOW_ANY, ALLOW_ANY, ALLOW_ANY, FILTER_TO_BOTH },
};
struct bsc_nat_parsed* bsc_nat_parse(struct msgb *msg)
{
struct sccp_parse_result result;
struct bsc_nat_parsed *parsed;
struct ipaccess_head *hh;
/* quick fail */
if (msg->len < 4)
return NULL;
parsed = talloc_zero(msg, struct bsc_nat_parsed);
if (!parsed)
return NULL;
/* more init */
parsed->ipa_proto = parsed->called_ssn = parsed->calling_ssn = -1;
parsed->sccp_type = parsed->bssap = parsed->gsm_type = -1;
/* start parsing */
hh = (struct ipaccess_head *) msg->data;
parsed->ipa_proto = hh->proto;
msg->l2h = &hh->data[0];
/* do a size check on the input */
if (ntohs(hh->len) != msgb_l2len(msg)) {
LOGP(DINP, LOGL_ERROR, "Wrong input length?\n");
talloc_free(parsed);
return NULL;
}
/* analyze sccp down here */
if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
memset(&result, 0, sizeof(result));
if (sccp_parse_header(msg, &result) != 0) {
talloc_free(parsed);
return 0;
}
if (msg->l3h && msgb_l3len(msg) < 3) {
LOGP(DNAT, LOGL_ERROR, "Not enough space or GSM payload\n");
talloc_free(parsed);
return 0;
}
parsed->sccp_type = sccp_determine_msg_type(msg);
parsed->src_local_ref = result.source_local_reference;
parsed->dest_local_ref = result.destination_local_reference;
parsed->called_ssn = result.called.ssn;
parsed->calling_ssn = result.calling.ssn;
/* in case of connection confirm we have no payload */
if (msg->l3h) {
parsed->bssap = msg->l3h[0];
parsed->gsm_type = msg->l3h[2];
}
}
return parsed;
}
int bsc_nat_filter_ipa(int dir, struct msgb *msg, struct bsc_nat_parsed *parsed)
{
int i;
/* go through the blacklist now */
for (i = 0; i < ARRAY_SIZE(black_list); ++i) {
/* ignore the rule? */
if (black_list[i].filter_dir != FILTER_TO_BOTH
&& black_list[i].filter_dir != dir)
continue;
/* the proto is not blacklisted */
if (black_list[i].ipa_proto != ALLOW_ANY
&& black_list[i].ipa_proto != parsed->ipa_proto)
continue;
if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
/* the SSN is not blacklisted */
if (black_list[i].dest_ssn != ALLOW_ANY
&& black_list[i].dest_ssn != parsed->called_ssn)
continue;
/* bssap */
if (black_list[i].bssap != ALLOW_ANY
&& black_list[i].bssap != parsed->bssap)
continue;
/* gsm */
if (black_list[i].gsm != ALLOW_ANY
&& black_list[i].gsm != parsed->gsm_type)
continue;
/* blacklisted */
LOGP(DNAT, LOGL_INFO, "Blacklisted with rule %d\n", i);
return 1;
} else {
/* blacklisted, we have no content sniffing yet */
LOGP(DNAT, LOGL_INFO, "Blacklisted with rule %d\n", i);
return 1;
}
}
/* go through the whitelust now */
for (i = 0; i < ARRAY_SIZE(white_list); ++i) {
/* ignore the rule? */
if (white_list[i].filter_dir != FILTER_TO_BOTH
&& white_list[i].filter_dir != dir)
continue;
/* the proto is not whitelisted */
if (white_list[i].ipa_proto != ALLOW_ANY
&& white_list[i].ipa_proto != parsed->ipa_proto)
continue;
if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
/* the SSN is not whitelisted */
if (white_list[i].dest_ssn != ALLOW_ANY
&& white_list[i].dest_ssn != parsed->called_ssn)
continue;
/* bssap */
if (white_list[i].bssap != ALLOW_ANY
&& white_list[i].bssap != parsed->bssap)
continue;
/* gsm */
if (white_list[i].gsm != ALLOW_ANY
&& white_list[i].gsm != parsed->gsm_type)
continue;
/* whitelisted */
LOGP(DNAT, LOGL_INFO, "Whitelisted with rule %d\n", i);
return 0;
} else {
/* whitelisted */
return 0;
}
}
return 1;
}

View File

@@ -0,0 +1,473 @@
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <openbsc/bsc_nat.h>
#include <openbsc/gsm_data.h>
#include <openbsc/bssap.h>
#include <openbsc/debug.h>
#include <openbsc/mgcp.h>
#include <openbsc/mgcp_internal.h>
#include <osmocore/talloc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg)
{
struct tlv_parsed tp;
u_int16_t cic;
u_int8_t timeslot;
u_int8_t multiplex;
if (!msg->l3h) {
LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n");
return -1;
}
if (msgb_l3len(msg) < 3) {
LOGP(DNAT, LOGL_ERROR, "Assignment message has not enough space for GSM0808.\n");
return -1;
}
tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0);
if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) {
LOGP(DNAT, LOGL_ERROR, "Circuit identity code not found in assignment message.\n");
return -1;
}
cic = ntohs(*(u_int16_t *)TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE));
timeslot = cic & 0x1f;
multiplex = (cic & ~0x1f) >> 5;
con->msc_timeslot = (32 * multiplex) + timeslot;
con->bsc_timeslot = con->msc_timeslot;
return 0;
}
void bsc_mgcp_clear(struct sccp_connections *con)
{
con->msc_timeslot = -1;
con->bsc_timeslot = -1;
}
void bsc_mgcp_free_endpoint(struct bsc_nat *nat, int i)
{
if (nat->bsc_endpoints[i].transaction_id) {
talloc_free(nat->bsc_endpoints[i].transaction_id);
nat->bsc_endpoints[i].transaction_id = NULL;
}
nat->bsc_endpoints[i].bsc = NULL;
mgcp_free_endp(&nat->mgcp_cfg->endpoints[i]);
}
void bsc_mgcp_free_endpoints(struct bsc_nat *nat)
{
int i;
for (i = 1; i < nat->mgcp_cfg->number_endpoints; ++i)
bsc_mgcp_free_endpoint(nat, i);
}
struct bsc_connection *bsc_mgcp_find_con(struct bsc_nat *nat, int endpoint)
{
struct sccp_connections *sccp;
llist_for_each_entry(sccp, &nat->sccp_connections, list_entry) {
if (sccp->msc_timeslot == -1)
continue;
if (mgcp_timeslot_to_endpoint(0, sccp->msc_timeslot) != endpoint)
continue;
return sccp->bsc;
}
LOGP(DMGCP, LOGL_ERROR, "Failed to find the connection.\n");
return NULL;
}
int bsc_mgcp_policy_cb(struct mgcp_config *cfg, int endpoint, int state, const char *transaction_id)
{
struct bsc_nat *nat;
struct bsc_endpoint *bsc_endp;
struct bsc_connection *bsc_con;
struct mgcp_endpoint *mgcp_endp;
struct msgb *bsc_msg;
nat = cfg->data;
bsc_endp = &nat->bsc_endpoints[endpoint];
mgcp_endp = &nat->mgcp_cfg->endpoints[endpoint];
bsc_con = bsc_mgcp_find_con(nat, endpoint);
if (!bsc_con) {
LOGP(DMGCP, LOGL_ERROR, "Did not find BSC for a new connection on 0x%x for %d\n", endpoint, state);
switch (state) {
case MGCP_ENDP_CRCX:
return MGCP_POLICY_REJECT;
break;
case MGCP_ENDP_DLCX:
return MGCP_POLICY_CONT;
break;
case MGCP_ENDP_MDCX:
return MGCP_POLICY_CONT;
break;
default:
LOGP(DMGCP, LOGL_FATAL, "Unhandled state: %d\n", state);
return MGCP_POLICY_CONT;
break;
}
}
if (bsc_endp->transaction_id) {
LOGP(DMGCP, LOGL_ERROR, "One transaction with id '%s' on 0x%x\n",
bsc_endp->transaction_id, endpoint);
talloc_free(bsc_endp->transaction_id);
}
bsc_endp->transaction_id = talloc_strdup(nat, transaction_id);
bsc_endp->bsc = bsc_con;
bsc_endp->pending_delete = state == MGCP_ENDP_DLCX;
/* we need to update some bits */
if (state == MGCP_ENDP_CRCX) {
struct sockaddr_in sock;
socklen_t len = sizeof(sock);
if (getpeername(bsc_con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Can not get the peername...%d/%s\n",
errno, strerror(errno));
} else {
mgcp_endp->bts = sock.sin_addr;
}
}
/* we need to generate a new and patched message */
bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length,
nat->mgcp_cfg->source_addr, mgcp_endp->rtp_port);
if (!bsc_msg) {
LOGP(DMGCP, LOGL_ERROR, "Failed to patch the msg.\n");
return MGCP_POLICY_CONT;
}
bsc_write_mgcp_msg(bsc_con, bsc_msg);
return MGCP_POLICY_DEFER;
}
/*
* We have received a msg from the BSC. We will see if we know
* this transaction and if it belongs to the BSC. Then we will
* need to patch the content to point to the local network and we
* need to update the I: that was assigned by the BSS.
*/
void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg)
{
struct msgb *output;
struct bsc_endpoint *bsc_endp = NULL;
struct mgcp_endpoint *endp = NULL;
int i, code;
char transaction_id[60];
/* Some assumption that our buffer is big enough.. and null terminate */
if (msgb_l2len(msg) > 2000) {
LOGP(DMGCP, LOGL_ERROR, "MGCP message too long.\n");
return;
}
msg->l2h[msgb_l2len(msg)] = '\0';
if (bsc_mgcp_parse_response((const char *) msg->l2h, &code, transaction_id) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to parse response code.\n");
return;
}
for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
if (bsc->nat->bsc_endpoints[i].bsc != bsc)
continue;
/* no one listening? a bug? */
if (!bsc->nat->bsc_endpoints[i].transaction_id)
continue;
if (strcmp(transaction_id, bsc->nat->bsc_endpoints[i].transaction_id) != 0)
continue;
endp = &bsc->nat->mgcp_cfg->endpoints[i];
bsc_endp = &bsc->nat->bsc_endpoints[i];
break;
}
if (!bsc_endp) {
LOGP(DMGCP, LOGL_ERROR, "Could not find active endpoint: %s for msg: '%s'\n",
transaction_id, (const char *) msg->l2h);
return;
}
/* free some stuff */
talloc_free(bsc_endp->transaction_id);
bsc_endp->transaction_id = NULL;
/* make it point to our endpoint */
endp->ci = bsc_mgcp_extract_ci((const char *) msg->l2h);
output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg),
bsc->nat->mgcp_cfg->source_addr, endp->rtp_port);
if (bsc_endp->pending_delete) {
mgcp_free_endp(endp);
bsc_endp->bsc = NULL;
bsc_endp->pending_delete = 0;
}
if (!output) {
LOGP(DMGCP, LOGL_ERROR, "Failed to rewrite MGCP msg.\n");
return;
}
if (write_queue_enqueue(&bsc->nat->mgcp_queue, output) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n");
msgb_free(output);
}
}
int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60])
{
/* we want to parse two strings */
return sscanf(str, "%3d %59s\n", code, transaction) != 2;
}
int bsc_mgcp_extract_ci(const char *str)
{
int ci;
char *res = strstr(str, "I: ");
if (!res)
return CI_UNUSED;
if (sscanf(res, "I: %d", &ci) != 1)
return CI_UNUSED;
return ci;
}
/* we need to replace some strings... */
struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port)
{
static const char *ip_str = "c=IN IP4 ";
static const char *aud_str = "m=audio ";
char buf[128];
char *running, *token;
struct msgb *output;
if (length > 4096 - 128) {
LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n");
return NULL;
}
output = msgb_alloc_headroom(4096, 128, "MGCP rewritten");
if (!output) {
LOGP(DMGCP, LOGL_ERROR, "Failed to allocate new MGCP msg.\n");
return NULL;
}
running = input;
output->l2h = output->data;
for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) {
int len = strlen(token);
int cr = len > 0 && token[len - 1] == '\r';
if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) {
output->l3h = msgb_put(output, strlen(ip_str));
memcpy(output->l3h, ip_str, strlen(ip_str));
output->l3h = msgb_put(output, strlen(ip));
memcpy(output->l3h, ip, strlen(ip));
if (cr) {
output->l3h = msgb_put(output, 2);
output->l3h[0] = '\r';
output->l3h[1] = '\n';
} else {
output->l3h = msgb_put(output, 1);
output->l3h[0] = '\n';
}
} else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) {
int payload;
if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) {
LOGP(DMGCP, LOGL_ERROR, "Could not parsed audio line.\n");
msgb_free(output);
return NULL;
}
snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s",
port, payload, cr ? "\r\n" : "\n");
buf[sizeof(buf)-1] = '\0';
output->l3h = msgb_put(output, strlen(buf));
memcpy(output->l3h, buf, strlen(buf));
} else {
output->l3h = msgb_put(output, len + 1);
memcpy(output->l3h, token, len);
output->l3h[len] = '\n';
}
}
return output;
}
static int mgcp_do_read(struct bsc_fd *fd)
{
struct bsc_nat *nat;
struct msgb *msg, *resp;
int rc;
nat = fd->data;
rc = read(fd->fd, nat->mgcp_msg, sizeof(nat->mgcp_msg) - 1);
if (rc <= 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to read errno: %d\n", errno);
return -1;
}
nat->mgcp_msg[rc] = '\0';
nat->mgcp_length = rc;
msg = msgb_alloc(sizeof(nat->mgcp_msg), "MGCP GW Read");
if (!msg) {
LOGP(DMGCP, LOGL_ERROR, "Failed to create buffer.\n");
return -1;
}
msg->l2h = msgb_put(msg, rc);
memcpy(msg->l2h, nat->mgcp_msg, msgb_l2len(msg));
resp = mgcp_handle_message(nat->mgcp_cfg, msg);
msgb_free(msg);
/* we do have a direct answer... e.g. AUEP */
if (resp) {
if (write_queue_enqueue(&nat->mgcp_queue, resp) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n");
msgb_free(resp);
}
}
return 0;
}
static int mgcp_do_write(struct bsc_fd *bfd, struct msgb *msg)
{
int rc;
rc = write(bfd->fd, msg->data, msg->len);
if (rc != msg->len) {
LOGP(DMGCP, LOGL_ERROR, "Failed to write msg to MGCP CallAgent.\n");
return -1;
}
return rc;
}
int bsc_mgcp_init(struct bsc_nat *nat)
{
int on;
struct sockaddr_in addr;
if (!nat->mgcp_cfg->call_agent_addr) {
LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n");
return -1;
}
if (nat->mgcp_cfg->bts_ip) {
LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n");
return -1;
}
nat->mgcp_queue.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0);
if (nat->mgcp_queue.bfd.fd < 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno);
return -1;
}
on = 1;
setsockopt(nat->mgcp_queue.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
addr.sin_family = AF_INET;
addr.sin_port = htons(nat->mgcp_cfg->source_port);
inet_aton(nat->mgcp_cfg->source_addr, &addr.sin_addr);
if (bind(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno);
close(nat->mgcp_queue.bfd.fd);
nat->mgcp_queue.bfd.fd = -1;
return -1;
}
addr.sin_port = htons(2727);
inet_aton(nat->mgcp_cfg->call_agent_addr, &addr.sin_addr);
if (connect(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n",
nat->mgcp_cfg->call_agent_addr, errno);
close(nat->mgcp_queue.bfd.fd);
nat->mgcp_queue.bfd.fd = -1;
return -1;
}
write_queue_init(&nat->mgcp_queue, 10);
nat->mgcp_queue.bfd.when = BSC_FD_READ;
nat->mgcp_queue.bfd.data = nat;
nat->mgcp_queue.read_cb = mgcp_do_read;
nat->mgcp_queue.write_cb = mgcp_do_write;
if (bsc_register_fd(&nat->mgcp_queue.bfd) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n");
close(nat->mgcp_queue.bfd.fd);
nat->mgcp_queue.bfd.fd = -1;
return -1;
}
/* some more MGCP config handling */
nat->mgcp_cfg->audio_payload = -1;
nat->mgcp_cfg->data = nat;
nat->mgcp_cfg->policy_cb = bsc_mgcp_policy_cb;
nat->bsc_endpoints = talloc_zero_array(nat,
struct bsc_endpoint,
nat->mgcp_cfg->number_endpoints + 1);
return 0;
}
void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc)
{
int i;
for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i];
if (bsc_endp->bsc != bsc)
continue;
bsc_endp->bsc = NULL;
bsc_endp->pending_delete = 0;
if (bsc_endp->transaction_id)
talloc_free(bsc_endp->transaction_id);
bsc_endp->transaction_id = NULL;
mgcp_free_endp(&bsc->nat->mgcp_cfg->endpoints[i]);
}
}

804
openbsc/src/nat/bsc_nat.c Normal file
View File

@@ -0,0 +1,804 @@
/* BSC Multiplexer/NAT */
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* (C) 2009 by Harald Welte <laforge@gnumonks.org>
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#define _GNU_SOURCE
#include <getopt.h>
#include <openbsc/debug.h>
#include <openbsc/bsc_msc.h>
#include <openbsc/bsc_nat.h>
#include <openbsc/bssap.h>
#include <openbsc/ipaccess.h>
#include <openbsc/abis_nm.h>
#include <openbsc/telnet_interface.h>
#include <osmocore/talloc.h>
#include <vty/vty.h>
#include <sccp/sccp.h>
struct debug_target *stderr_target;
static const char *config_file = "bsc-nat.cfg";
static char *msc_address = "127.0.0.1";
static struct in_addr local_addr;
static struct bsc_msc_connection *msc_con;
static struct bsc_fd bsc_listen;
static struct bsc_nat *nat;
static void bsc_write(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length);
static void remove_bsc_connection(struct bsc_connection *connection);
struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num)
{
struct bsc_config *conf;
llist_for_each_entry(conf, &nat->bsc_configs, entry)
if (conf->nr == num)
return conf;
return NULL;
}
/*
* below are stubs we need to link
*/
int nm_state_event(enum nm_evt evt, u_int8_t obj_class, void *obj,
struct gsm_nm_state *old_state, struct gsm_nm_state *new_state)
{
return -1;
}
void input_event(int event, enum e1inp_sign_type type, struct gsm_bts_trx *trx)
{}
int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
{
return -1;
}
static void send_reset_ack(struct bsc_connection *bsc)
{
static const u_int8_t gsm_reset_ack[] = {
0x00, 0x13, 0xfd,
0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
0x00, 0x01, 0x31,
};
bsc_write(bsc, gsm_reset_ack, sizeof(gsm_reset_ack));
}
static void send_id_ack(struct bsc_connection *bsc)
{
static const u_int8_t id_ack[] = {
0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK
};
bsc_write(bsc, id_ack, sizeof(id_ack));
}
static void send_id_req(struct bsc_connection *bsc)
{
static const u_int8_t id_req[] = {
0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
0x01, IPAC_IDTAG_UNIT,
0x01, IPAC_IDTAG_MACADDR,
0x01, IPAC_IDTAG_LOCATION1,
0x01, IPAC_IDTAG_LOCATION2,
0x01, IPAC_IDTAG_EQUIPVERS,
0x01, IPAC_IDTAG_SWVERSION,
0x01, IPAC_IDTAG_UNITNAME,
0x01, IPAC_IDTAG_SERNR,
};
bsc_write(bsc, id_req, sizeof(id_req));
}
static void nat_send_rlsd(struct sccp_connections *conn)
{
struct sccp_connection_released *rel;
struct msgb *msg;
msg = msgb_alloc_headroom(4096, 128, "rlsd");
if (!msg) {
LOGP(DNAT, LOGL_ERROR, "Failed to allocate clear command.\n");
return;
}
msg->l2h = msgb_put(msg, sizeof(*rel));
rel = (struct sccp_connection_released *) msg->l2h;
rel->type = SCCP_MSG_TYPE_RLSD;
rel->release_cause = SCCP_RELEASE_CAUSE_SCCP_FAILURE;
rel->destination_local_reference = conn->remote_ref;
rel->source_local_reference = conn->patched_ref;
ipaccess_prepend_header(msg, IPAC_PROTO_SCCP);
if (write_queue_enqueue(&msc_con->write_queue, msg) != 0) {
LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n");
msgb_free(msg);
}
}
static void send_mgcp_reset(struct bsc_connection *bsc)
{
static const u_int8_t mgcp_reset[] = {
"RSIP 1 13@mgw MGCP 1.0\r\n"
};
bsc_write_mgcp(bsc, mgcp_reset, sizeof mgcp_reset - 1);
}
/*
* Below is the handling of messages coming
* from the MSC and need to be forwarded to
* a real BSC.
*/
static void initialize_msc_if_needed()
{
static int init = 0;
init = 1;
/* do we need to send a GSM 08.08 message here? */
}
/*
* Currently we are lacking refcounting so we need to copy each message.
*/
static void bsc_write(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length)
{
struct msgb *msg;
if (length > 4096) {
LOGP(DINP, LOGL_ERROR, "Can not send message of that size.\n");
return;
}
msg = msgb_alloc(4096, "to-bsc");
if (!msg) {
LOGP(DINP, LOGL_ERROR, "Failed to allocate memory for BSC msg.\n");
return;
}
msgb_put(msg, length);
memcpy(msg->data, data, length);
if (write_queue_enqueue(&bsc->write_queue, msg) != 0) {
LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n");
msgb_free(msg);
}
}
static int forward_sccp_to_bts(struct msgb *msg)
{
struct sccp_connections *con;
struct bsc_connection *bsc;
struct bsc_nat_parsed *parsed;
/* filter, drop, patch the message? */
parsed = bsc_nat_parse(msg);
if (!parsed) {
LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
return -1;
}
if (bsc_nat_filter_ipa(DIR_BSC, msg, parsed))
goto exit;
/* Route and modify the SCCP packet */
if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
switch (parsed->sccp_type) {
case SCCP_MSG_TYPE_UDT:
/* forward UDT messages to every BSC */
goto send_to_all;
break;
case SCCP_MSG_TYPE_RLSD:
case SCCP_MSG_TYPE_CREF:
case SCCP_MSG_TYPE_DT1:
case SCCP_MSG_TYPE_IT:
con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
if (parsed->gsm_type == BSS_MAP_MSG_ASSIGMENT_RQST) {
if (con) {
if (bsc_mgcp_assign(con, msg) != 0)
LOGP(DNAT, LOGL_ERROR, "Failed to assign...\n");
} else
LOGP(DNAT, LOGL_ERROR, "Assignment command but no BSC.\n");
}
break;
case SCCP_MSG_TYPE_CC:
con = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
if (!con || update_sccp_src_ref(con, parsed) != 0)
goto exit;
break;
case SCCP_MSG_TYPE_RLC:
LOGP(DNAT, LOGL_ERROR, "Unexpected release complete from MSC.\n");
goto exit;
break;
case SCCP_MSG_TYPE_CR:
/* MSC never opens a SCCP connection, fall through */
default:
goto exit;
}
if (!con)
LOGP(DNAT, LOGL_ERROR, "Unknown connection for msg type: 0x%x.\n", parsed->sccp_type);
}
talloc_free(parsed);
if (!con)
return -1;
if (!con->bsc->authenticated) {
LOGP(DNAT, LOGL_ERROR, "Selected BSC not authenticated.\n");
return -1;
}
bsc_write(con->bsc, msg->data, msg->len);
return 0;
send_to_all:
/*
* Filter Paging from the network. We do not want to send a PAGING
* Command to every BSC in our network. We will analys the PAGING
* message and then send it to the authenticated messages...
*/
if (parsed->ipa_proto == IPAC_PROTO_SCCP && parsed->gsm_type == BSS_MAP_MSG_PAGING) {
bsc = bsc_nat_find_bsc(nat, msg);
if (bsc)
bsc_write(bsc, msg->data, msg->len);
else
LOGP(DNAT, LOGL_ERROR, "Could not determine BSC for paging.\n");
goto exit;
}
/* currently send this to every BSC connected */
llist_for_each_entry(bsc, &nat->bsc_connections, list_entry) {
if (!bsc->authenticated)
continue;
bsc_write(bsc, msg->data, msg->len);
}
exit:
talloc_free(parsed);
return 0;
}
static void msc_connection_was_lost(struct bsc_msc_connection *con)
{
struct bsc_connection *bsc, *tmp;
LOGP(DMSC, LOGL_ERROR, "Closing all connections downstream.\n");
llist_for_each_entry_safe(bsc, tmp, &nat->bsc_connections, list_entry)
remove_bsc_connection(bsc);
bsc_mgcp_free_endpoints(nat);
bsc_msc_schedule_connect(con);
}
static int ipaccess_msc_read_cb(struct bsc_fd *bfd)
{
int error;
struct msgb *msg = ipaccess_read_msg(bfd, &error);
struct ipaccess_head *hh;
if (!msg) {
if (error == 0) {
LOGP(DNAT, LOGL_FATAL, "The connection the MSC was lost, exiting\n");
bsc_msc_lost(msc_con);
return -1;
}
LOGP(DNAT, LOGL_ERROR, "Failed to parse ip access message: %d\n", error);
return -1;
}
LOGP(DNAT, LOGL_DEBUG, "MSG from MSC: %s proto: %d\n", hexdump(msg->data, msg->len), msg->l2h[0]);
/* handle base message handling */
hh = (struct ipaccess_head *) msg->data;
ipaccess_rcvmsg_base(msg, bfd);
/* initialize the networking. This includes sending a GSM08.08 message */
if (hh->proto == IPAC_PROTO_IPACCESS && msg->l2h[0] == IPAC_MSGT_ID_ACK)
initialize_msc_if_needed();
else if (hh->proto == IPAC_PROTO_SCCP)
forward_sccp_to_bts(msg);
msgb_free(msg);
return 0;
}
static int ipaccess_msc_write_cb(struct bsc_fd *bfd, struct msgb *msg)
{
int rc;
rc = write(bfd->fd, msg->data, msg->len);
if (rc != msg->len) {
LOGP(DNAT, LOGL_ERROR, "Failed to write MSG to MSC.\n");
return -1;
}
return rc;
}
/*
* Below is the handling of messages coming
* from the BSC and need to be forwarded to
* a real BSC.
*/
/*
* Remove the connection from the connections list,
* remove it from the patching of SCCP header lists
* as well. Maybe in the future even close connection..
*/
static void remove_bsc_connection(struct bsc_connection *connection)
{
struct sccp_connections *sccp_patch, *tmp;
bsc_unregister_fd(&connection->write_queue.bfd);
close(connection->write_queue.bfd.fd);
write_queue_clear(&connection->write_queue);
llist_del(&connection->list_entry);
/* stop the timeout timer */
bsc_del_timer(&connection->id_timeout);
/* remove all SCCP connections */
llist_for_each_entry_safe(sccp_patch, tmp, &nat->sccp_connections, list_entry) {
if (sccp_patch->bsc != connection)
continue;
nat_send_rlsd(sccp_patch);
sccp_connection_destroy(sccp_patch);
}
/* close endpoints allocated by this BSC */
bsc_mgcp_clear_endpoints_for(connection);
talloc_free(connection);
}
static void ipaccess_close_bsc(void *data)
{
struct bsc_connection *conn = data;
LOGP(DNAT, LOGL_ERROR, "BSC didn't respond to identity request. Closing.\n");
remove_bsc_connection(conn);
}
static void ipaccess_auth_bsc(struct tlv_parsed *tvp, struct bsc_connection *bsc)
{
struct bsc_config *conf;
const char* token = (const char *) TLVP_VAL(tvp, IPAC_IDTAG_UNITNAME);
llist_for_each_entry(conf, &bsc->nat->bsc_configs, entry) {
if (strcmp(conf->token, token) == 0) {
bsc->authenticated = 1;
bsc->cfg = conf;
bsc_del_timer(&bsc->id_timeout);
LOGP(DNAT, LOGL_NOTICE, "Authenticated bsc nr: %d lac: %d\n", conf->nr, conf->lac);
break;
}
}
}
static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg)
{
struct sccp_connections *con;
struct bsc_nat_parsed *parsed;
/* Parse and filter messages */
parsed = bsc_nat_parse(msg);
if (!parsed) {
LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
msgb_free(msg);
return -1;
}
if (bsc_nat_filter_ipa(DIR_MSC, msg, parsed))
goto exit;
/*
* check authentication after filtering to not reject auth
* responses coming from the BSC. We have to make sure that
* nothing from the exit path will forward things to the MSC
*/
if (!bsc->authenticated) {
LOGP(DNAT, LOGL_ERROR, "BSC is not authenticated.\n");
msgb_free(msg);
return -1;
}
/* modify the SCCP entries */
if (parsed->ipa_proto == IPAC_PROTO_SCCP) {
switch (parsed->sccp_type) {
case SCCP_MSG_TYPE_CR:
if (create_sccp_src_ref(bsc, msg, parsed) != 0)
goto exit2;
con = patch_sccp_src_ref_to_msc(msg, parsed, nat);
break;
case SCCP_MSG_TYPE_RLSD:
case SCCP_MSG_TYPE_CREF:
case SCCP_MSG_TYPE_DT1:
case SCCP_MSG_TYPE_CC:
case SCCP_MSG_TYPE_IT:
con = patch_sccp_src_ref_to_msc(msg, parsed, nat);
break;
case SCCP_MSG_TYPE_RLC:
con = patch_sccp_src_ref_to_msc(msg, parsed, nat);
remove_sccp_src_ref(bsc, msg, parsed);
break;
case SCCP_MSG_TYPE_UDT:
/* simply forward everything */
con = NULL;
break;
default:
LOGP(DNAT, LOGL_ERROR, "Not forwarding to msc sccp type: 0x%x\n", parsed->sccp_type);
con = NULL;
goto exit2;
break;
}
} else if (parsed->ipa_proto == NAT_IPAC_PROTO_MGCP) {
bsc_mgcp_forward(bsc, msg);
goto exit2;
} else {
LOGP(DNAT, LOGL_ERROR, "Not forwarding unknown stream id: 0x%x\n", parsed->ipa_proto);
goto exit2;
}
if (con && con->bsc != bsc) {
LOGP(DNAT, LOGL_ERROR, "Found the wrong entry.\n");
goto exit2;
}
/* send the non-filtered but maybe modified msg */
if (write_queue_enqueue(&msc_con->write_queue, msg) != 0) {
LOGP(DNAT, LOGL_ERROR, "Can not queue message for the MSC.\n");
msgb_free(msg);
}
talloc_free(parsed);
return 0;
exit:
/* if we filter out the reset send an ack to the BSC */
if (parsed->bssap == 0 && parsed->gsm_type == BSS_MAP_MSG_RESET) {
send_reset_ack(bsc);
send_reset_ack(bsc);
} else if (parsed->ipa_proto == IPAC_PROTO_IPACCESS) {
/* do we know who is handling this? */
if (msg->l2h[0] == IPAC_MSGT_ID_RESP) {
struct tlv_parsed tvp;
ipaccess_idtag_parse(&tvp,
(unsigned char *) msg->l2h + 2,
msgb_l2len(msg) - 2);
if (TLVP_PRESENT(&tvp, IPAC_IDTAG_UNITNAME))
ipaccess_auth_bsc(&tvp, bsc);
}
goto exit2;
}
exit2:
talloc_free(parsed);
msgb_free(msg);
return -1;
}
static int ipaccess_bsc_read_cb(struct bsc_fd *bfd)
{
int error;
struct bsc_connection *bsc = bfd->data;
struct msgb *msg = ipaccess_read_msg(bfd, &error);
if (!msg) {
if (error == 0) {
LOGP(DNAT, LOGL_ERROR, "The connection to the BSC was lost. Cleaning it\n");
remove_bsc_connection(bsc);
} else {
LOGP(DNAT, LOGL_ERROR, "Failed to parse ip access message: %d\n", error);
}
return -1;
}
LOGP(DNAT, LOGL_DEBUG, "MSG from BSC: %s proto: %d\n", hexdump(msg->data, msg->len), msg->l2h[0]);
/* Handle messages from the BSC */
/* FIXME: Currently no PONG is sent to the BSC */
/* FIXME: Currently no ID ACK is sent to the BSC */
forward_sccp_to_msc(bsc, msg);
return 0;
}
static int ipaccess_bsc_write_cb(struct bsc_fd *bfd, struct msgb *msg)
{
int rc;
rc = write(bfd->fd, msg->data, msg->len);
if (rc != msg->len)
LOGP(DNAT, LOGL_ERROR, "Failed to write message to the BSC.\n");
return rc;
}
static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what)
{
struct bsc_connection *bsc;
int ret;
struct sockaddr_in sa;
socklen_t sa_len = sizeof(sa);
if (!(what & BSC_FD_READ))
return 0;
ret = accept(bfd->fd, (struct sockaddr *) &sa, &sa_len);
if (ret < 0) {
perror("accept");
return ret;
}
/*
* if we are not connected to a msc... just close the socket
*/
if (!msc_con->is_connected) {
LOGP(DNAT, LOGL_NOTICE, "Disconnecting BSC due lack of MSC connection.\n");
close(ret);
return 0;
}
/* todo... do something with the connection */
/* todo... use GNUtls to see if we want to trust this as a BTS */
/*
*
*/
bsc = bsc_connection_alloc(nat);
if (!bsc) {
LOGP(DNAT, LOGL_ERROR, "Failed to allocate BSC struct.\n");
close(ret);
return -1;
}
write_queue_init(&bsc->write_queue, 100);
bsc->write_queue.bfd.data = bsc;
bsc->write_queue.bfd.fd = ret;
bsc->write_queue.read_cb = ipaccess_bsc_read_cb;
bsc->write_queue.write_cb = ipaccess_bsc_write_cb;
bsc->write_queue.bfd.when = BSC_FD_READ;
if (bsc_register_fd(&bsc->write_queue.bfd) < 0) {
LOGP(DNAT, LOGL_ERROR, "Failed to register BSC fd.\n");
close(ret);
talloc_free(bsc);
return -2;
}
LOGP(DNAT, LOGL_NOTICE, "Registered new BSC\n");
llist_add(&bsc->list_entry, &nat->bsc_connections);
send_id_ack(bsc);
send_id_req(bsc);
send_mgcp_reset(bsc);
/*
* start the hangup timer
*/
bsc->id_timeout.data = bsc;
bsc->id_timeout.cb = ipaccess_close_bsc;
bsc_schedule_timer(&bsc->id_timeout, 2, 0);
return 0;
}
static int listen_for_bsc(struct bsc_fd *bfd, struct in_addr *in_addr, int port)
{
struct sockaddr_in addr;
int ret, on = 1;
bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
bfd->cb = ipaccess_listen_bsc_cb;
bfd->when = BSC_FD_READ;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = in_addr->s_addr;
setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
if (ret < 0) {
fprintf(stderr, "Could not bind the BSC socket %s\n",
strerror(errno));
return -EIO;
}
ret = listen(bfd->fd, 1);
if (ret < 0) {
perror("listen");
return ret;
}
ret = bsc_register_fd(bfd);
if (ret < 0) {
perror("register_listen_fd");
return ret;
}
return 0;
}
static void print_usage()
{
printf("Usage: bsc_nat\n");
}
static void print_help()
{
printf(" Some useful help...\n");
printf(" -h --help this text\n");
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
printf(" -s --disable-color\n");
printf(" -c --config-file filename The config file to use.\n");
printf(" -m --msc=IP. The address of the MSC.\n");
printf(" -l --local=IP. The local address of this BSC.\n");
}
static void handle_options(int argc, char** argv)
{
while (1) {
int option_index = 0, c;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"debug", 1, 0, 'd'},
{"config-file", 1, 0, 'c'},
{"disable-color", 0, 0, 's'},
{"timestamp", 0, 0, 'T'},
{"msc", 1, 0, 'm'},
{"local", 1, 0, 'l'},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "hd:sTPc:m:l:",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'h':
print_usage();
print_help();
exit(0);
case 's':
debug_set_use_color(stderr_target, 0);
break;
case 'd':
debug_parse_category_mask(stderr_target, optarg);
break;
case 'c':
config_file = strdup(optarg);
break;
case 'T':
debug_set_print_timestamp(stderr_target, 1);
break;
case 'm':
msc_address = strdup(optarg);
break;
case 'l':
inet_aton(optarg, &local_addr);
break;
default:
/* ignore */
break;
}
}
}
static void signal_handler(int signal)
{
switch (signal) {
case SIGABRT:
/* in case of abort, we want to obtain a talloc report
* and then return to the caller, who will abort the process */
case SIGUSR1:
talloc_report_full(tall_bsc_ctx, stderr);
break;
default:
break;
}
}
int main(int argc, char** argv)
{
debug_init();
stderr_target = debug_target_create_stderr();
debug_add_target(stderr_target);
debug_set_all_filter(stderr_target, 1);
/* parse options */
local_addr.s_addr = INADDR_ANY;
handle_options(argc, argv);
nat = bsc_nat_alloc();
if (!nat) {
fprintf(stderr, "Failed to allocate the BSC nat.\n");
return -4;
}
nat->mgcp_cfg = talloc_zero(nat, struct mgcp_config);
/* init vty and parse */
bsc_nat_vty_init(nat);
telnet_init(NULL, 4244);
if (mgcp_parse_config(config_file, nat->mgcp_cfg) < 0) {
fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
return -3;
}
/* seed the PRNG */
srand(time(NULL));
/*
* Setup the MGCP code..
*/
if (bsc_mgcp_init(nat) != 0)
return -4;
/* connect to the MSC */
msc_con = bsc_msc_create(msc_address, 5000);
if (!msc_con) {
fprintf(stderr, "Creating a bsc_msc_connection failed.\n");
exit(1);
}
msc_con->connection_loss = msc_connection_was_lost;
msc_con->write_queue.read_cb = ipaccess_msc_read_cb;
msc_con->write_queue.write_cb = ipaccess_msc_write_cb;;
bsc_msc_connect(msc_con);
/* wait for the BSC */
if (listen_for_bsc(&bsc_listen, &local_addr, 5000) < 0) {
fprintf(stderr, "Failed to listen for BSC.\n");
exit(1);
}
signal(SIGABRT, &signal_handler);
signal(SIGUSR1, &signal_handler);
signal(SIGPIPE, SIG_IGN);
while (1) {
bsc_select_main(0);
}
return 0;
}

View File

@@ -0,0 +1,165 @@
/* BSC Multiplexer/NAT Utilities */
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <openbsc/bsc_nat.h>
#include <openbsc/gsm_data.h>
#include <openbsc/bssap.h>
#include <openbsc/debug.h>
#include <openbsc/ipaccess.h>
#include <osmocore/linuxlist.h>
#include <osmocore/talloc.h>
#include <sccp/sccp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
struct bsc_nat *bsc_nat_alloc(void)
{
struct bsc_nat *nat = talloc_zero(tall_bsc_ctx, struct bsc_nat);
if (!nat)
return NULL;
INIT_LLIST_HEAD(&nat->sccp_connections);
INIT_LLIST_HEAD(&nat->bsc_connections);
INIT_LLIST_HEAD(&nat->bsc_configs);
return nat;
}
struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat)
{
struct bsc_connection *con = talloc_zero(nat, struct bsc_connection);
if (!con)
return NULL;
con->nat = nat;
return con;
}
struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac)
{
struct bsc_config *conf = talloc_zero(nat, struct bsc_config);
if (!conf)
return NULL;
conf->token = talloc_strdup(conf, token);
conf->lac = lac;
conf->nr = nat->num_bsc;
conf->nat = nat;
llist_add(&conf->entry, &nat->bsc_configs);
++nat->num_bsc;
return conf;
}
void sccp_connection_destroy(struct sccp_connections *conn)
{
LOGP(DNAT, LOGL_DEBUG, "Destroy 0x%x <-> 0x%x mapping for con %p\n",
sccp_src_ref_to_int(&conn->real_ref),
sccp_src_ref_to_int(&conn->patched_ref), conn->bsc);
bsc_mgcp_clear(conn);
llist_del(&conn->list_entry);
talloc_free(conn);
}
struct bsc_connection *bsc_nat_find_bsc(struct bsc_nat *nat, struct msgb *msg)
{
struct bsc_connection *bsc;
int data_length;
const u_int8_t *data;
struct tlv_parsed tp;
int i = 0;
if (!msg->l3h || msgb_l3len(msg) < 3) {
LOGP(DNAT, LOGL_ERROR, "Paging message is too short.\n");
return NULL;
}
tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0);
if (!TLVP_PRESENT(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST)) {
LOGP(DNAT, LOGL_ERROR, "No CellIdentifier List inside paging msg.\n");
return NULL;
}
data_length = TLVP_LEN(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
data = TLVP_VAL(&tp, GSM0808_IE_CELL_IDENTIFIER_LIST);
if (data[0] != CELL_IDENT_LAC) {
LOGP(DNAT, LOGL_ERROR, "Unhandled cell ident discrminator: %d\n", data[0]);
return NULL;
}
/* Currently we only handle one BSC */
for (i = 1; i < data_length - 1; i += 2) {
unsigned int _lac = ntohs(*(unsigned int *) &data[i]);
llist_for_each_entry(bsc, &nat->bsc_connections, list_entry) {
if (!bsc->cfg)
continue;
if (!bsc->authenticated || _lac != bsc->cfg->lac)
continue;
return bsc;
}
}
return NULL;
}
int bsc_write_mgcp(struct bsc_connection *bsc, const u_int8_t *data, unsigned int length)
{
struct msgb *msg;
if (length > 4096 - 128) {
LOGP(DINP, LOGL_ERROR, "Can not send message of that size.\n");
return -1;
}
msg = msgb_alloc_headroom(4096, 128, "to-bsc");
if (!msg) {
LOGP(DINP, LOGL_ERROR, "Failed to allocate memory for BSC msg.\n");
return -1;
}
/* copy the data */
msg->l3h = msgb_put(msg, length);
memcpy(msg->l3h, data, length);
return bsc_write_mgcp_msg(bsc, msg);
}
int bsc_write_mgcp_msg(struct bsc_connection *bsc, struct msgb *msg)
{
/* prepend the header */
ipaccess_prepend_header(msg, NAT_IPAC_PROTO_MGCP);
if (write_queue_enqueue(&bsc->write_queue, msg) != 0) {
LOGP(DINP, LOGL_ERROR, "Failed to enqueue the write.\n");
msgb_free(msg);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,228 @@
/* OpenBSC NAT interface to quagga VTY */
/* (C) 2010 by Holger Hans Peter Freyther
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <vty/command.h>
#include <vty/buffer.h>
#include <vty/vty.h>
#include <openbsc/bsc_nat.h>
#include <openbsc/gsm_04_08.h>
#include <openbsc/mgcp.h>
#include <openbsc/vty.h>
#include <osmocore/talloc.h>
#include <sccp/sccp.h>
#include <stdlib.h>
static struct bsc_nat *_nat;
static struct cmd_node nat_node = {
NAT_NODE,
"%s(nat)#",
1,
};
static struct cmd_node bsc_node = {
BSC_NODE,
"%s(bsc)#",
1,
};
static int config_write_nat(struct vty *vty)
{
vty_out(vty, "nat%s", VTY_NEWLINE);
return CMD_SUCCESS;
}
static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
{
vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
vty_out(vty, " lac %u%s", bsc->lac, VTY_NEWLINE);
}
static int config_write_bsc(struct vty *vty)
{
struct bsc_config *bsc;
llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
config_write_bsc_single(vty, bsc);
return CMD_SUCCESS;
}
DEFUN(show_sccp, show_sccp_cmd, "show connections sccp",
SHOW_STR "Display information about current SCCP connections")
{
struct sccp_connections *con;
llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
vty_out(vty, "SCCP for BSC: Nr: %d lac: %d BSC ref: 0x%x Local ref: 0x%x MSC/BSC mux: 0x%x/0x%x%s",
con->bsc->cfg ? con->bsc->cfg->nr : -1,
con->bsc->cfg ? con->bsc->cfg->lac : -1,
sccp_src_ref_to_int(&con->real_ref),
sccp_src_ref_to_int(&con->patched_ref),
con->msc_timeslot, con->bsc_timeslot,
VTY_NEWLINE);
}
return CMD_SUCCESS;
}
DEFUN(show_bsc, show_bsc_cmd, "show connections bsc",
SHOW_STR "Display information about current BSCs")
{
struct bsc_connection *con;
llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
vty_out(vty, "BSC lac: %d, %d auth: %d fd: %d%s",
con->cfg ? con->cfg->nr : -1,
con->cfg ? con->cfg->lac : -1,
con->authenticated, con->write_queue.bfd.fd, VTY_NEWLINE);
}
return CMD_SUCCESS;
}
DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
SHOW_STR "Display information about known BSC configs")
{
struct bsc_config *conf;
llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s",
conf->token, conf->lac, conf->nr, VTY_NEWLINE);
}
return CMD_SUCCESS;
}
DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
{
vty->index = _nat;
vty->node = NAT_NODE;
return CMD_SUCCESS;
}
/* per BSC configuration */
DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure\n")
{
int bsc_nr = atoi(argv[0]);
struct bsc_config *bsc;
if (bsc_nr > _nat->num_bsc) {
vty_out(vty, "%% The next unused BSC number is %u%s",
_nat->num_bsc, VTY_NEWLINE);
return CMD_WARNING;
} else if (bsc_nr == _nat->num_bsc) {
/* allocate a new one */
bsc = bsc_config_alloc(_nat, "unknown", 0);
} else
bsc = bsc_config_num(_nat, bsc_nr);
if (!bsc)
return CMD_WARNING;
vty->index = bsc;
vty->node = BSC_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
{
struct bsc_config *conf = vty->index;
if (conf->token)
talloc_free(conf->token);
conf->token = talloc_strdup(conf, argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
"Set the Location Area Code (LAC) of this BSC\n")
{
struct bsc_config *tmp;
struct bsc_config *conf = vty->index;
int lac = atoi(argv[0]);
if (lac < 0 || lac > 0xffff) {
vty_out(vty, "%% LAC %d is not in the valid range (0-65535)%s",
lac, VTY_NEWLINE);
return CMD_WARNING;
}
if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
lac, VTY_NEWLINE);
return CMD_WARNING;
}
/* verify that the LACs are unique */
llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
if (tmp->lac == lac) {
vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
return CMD_ERR_INCOMPLETE;
}
}
conf->lac = lac;
return CMD_SUCCESS;
}
int bsc_nat_vty_init(struct bsc_nat *nat)
{
_nat = nat;
cmd_init(1);
vty_init();
/* show commands */
install_element(VIEW_NODE, &show_sccp_cmd);
install_element(VIEW_NODE, &show_bsc_cmd);
install_element(VIEW_NODE, &show_bsc_cfg_cmd);
openbsc_vty_add_cmds();
/* nat group */
install_element(CONFIG_NODE, &cfg_nat_cmd);
install_node(&nat_node, config_write_nat);
install_default(NAT_NODE);
/* BSC subgroups */
install_element(NAT_NODE, &cfg_bsc_cmd);
install_node(&bsc_node, config_write_bsc);
install_default(BSC_NODE);
install_element(BSC_NODE, &cfg_bsc_token_cmd);
install_element(BSC_NODE, &cfg_bsc_lac_cmd);
mgcp_vty_init();
return 0;
}
/* called by the telnet interface... we have our own init above */
void bsc_vty_init()
{}

203
openbsc/src/nat/bsc_sccp.c Normal file
View File

@@ -0,0 +1,203 @@
/* SCCP patching and handling routines */
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <openbsc/debug.h>
#include <openbsc/bsc_nat.h>
#include <sccp/sccp.h>
#include <osmocore/talloc.h>
#include <string.h>
static int equal(struct sccp_source_reference *ref1, struct sccp_source_reference *ref2)
{
return memcmp(ref1, ref2, sizeof(*ref1)) == 0;
}
/*
* SCCP patching below
*/
/* check if we are using this ref for patched already */
static int sccp_ref_is_free(struct sccp_source_reference *ref, struct bsc_nat *nat)
{
struct sccp_connections *conn;
llist_for_each_entry(conn, &nat->sccp_connections, list_entry) {
if (memcmp(ref, &conn->patched_ref, sizeof(*ref)) == 0)
return -1;
}
return 0;
}
/* copied from sccp.c */
static int assign_src_local_reference(struct sccp_source_reference *ref, struct bsc_nat *nat)
{
static u_int32_t last_ref = 0x50000;
int wrapped = 0;
do {
struct sccp_source_reference reference;
reference.octet1 = (last_ref >> 0) & 0xff;
reference.octet2 = (last_ref >> 8) & 0xff;
reference.octet3 = (last_ref >> 16) & 0xff;
++last_ref;
/* do not use the reversed word and wrap around */
if ((last_ref & 0x00FFFFFF) == 0x00FFFFFF) {
LOGP(DNAT, LOGL_NOTICE, "Wrapped searching for a free code\n");
last_ref = 0;
++wrapped;
}
if (sccp_ref_is_free(&reference, nat) == 0) {
*ref = reference;
return 0;
}
} while (wrapped != 2);
LOGP(DNAT, LOGL_ERROR, "Finding a free reference failed\n");
return -1;
}
int create_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed)
{
struct sccp_connections *conn;
conn = talloc_zero(bsc->nat, struct sccp_connections);
if (!conn) {
LOGP(DNAT, LOGL_ERROR, "Memory allocation failure.\n");
return -1;
}
conn->bsc = bsc;
conn->real_ref = *parsed->src_local_ref;
if (assign_src_local_reference(&conn->patched_ref, bsc->nat) != 0) {
LOGP(DNAT, LOGL_ERROR, "Failed to assign a ref.\n");
talloc_free(conn);
return -1;
}
llist_add(&conn->list_entry, &bsc->nat->sccp_connections);
LOGP(DNAT, LOGL_DEBUG, "Created 0x%x <-> 0x%x mapping for con %p\n",
sccp_src_ref_to_int(&conn->real_ref),
sccp_src_ref_to_int(&conn->patched_ref), bsc);
return 0;
}
int update_sccp_src_ref(struct sccp_connections *sccp, struct bsc_nat_parsed *parsed)
{
if (!parsed->dest_local_ref || !parsed->src_local_ref) {
LOGP(DNAT, LOGL_ERROR, "CC MSG should contain both local and dest address.\n");
return -1;
}
sccp->remote_ref = *parsed->src_local_ref;
LOGP(DNAT, LOGL_DEBUG, "Updating 0x%x to remote 0x%x on %p\n",
sccp_src_ref_to_int(&sccp->patched_ref),
sccp_src_ref_to_int(&sccp->remote_ref), sccp->bsc);
return 0;
}
void remove_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed)
{
struct sccp_connections *conn;
llist_for_each_entry(conn, &bsc->nat->sccp_connections, list_entry) {
if (memcmp(parsed->src_local_ref,
&conn->patched_ref, sizeof(conn->patched_ref)) == 0) {
sccp_connection_destroy(conn);
return;
}
}
LOGP(DNAT, LOGL_ERROR, "Can not remove connection: 0x%x\n",
sccp_src_ref_to_int(parsed->src_local_ref));
}
/*
* We have a message from the MSC to the BSC. The MSC is using
* an address that was assigned by the MUX, we need to update the
* dest reference to the real network.
*/
struct sccp_connections *patch_sccp_src_ref_to_bsc(struct msgb *msg,
struct bsc_nat_parsed *parsed,
struct bsc_nat *nat)
{
struct sccp_connections *conn;
if (!parsed->dest_local_ref) {
LOGP(DNAT, LOGL_ERROR, "MSG should contain dest_local_ref.\n");
return NULL;
}
llist_for_each_entry(conn, &nat->sccp_connections, list_entry) {
if (!equal(parsed->dest_local_ref, &conn->patched_ref))
continue;
/* Change the dest address to the real one */
*parsed->dest_local_ref = conn->real_ref;
return conn;
}
return NULL;
}
/*
* These are message to the MSC. We will need to find the BSC
* Connection by either the SRC or the DST local reference.
*
* In case of a CR we need to work by the SRC local reference
* in all other cases we need to work by the destination local
* reference..
*/
struct sccp_connections *patch_sccp_src_ref_to_msc(struct msgb *msg,
struct bsc_nat_parsed *parsed,
struct bsc_nat *nat)
{
struct sccp_connections *conn;
llist_for_each_entry(conn, &nat->sccp_connections, list_entry) {
if (parsed->src_local_ref) {
if (equal(parsed->src_local_ref, &conn->real_ref)) {
*parsed->src_local_ref = conn->patched_ref;
return conn;
}
} else if (parsed->dest_local_ref) {
if (equal(parsed->dest_local_ref, &conn->remote_ref))
return conn;
} else {
LOGP(DNAT, LOGL_ERROR, "Header has neither loc/dst ref.\n");
return NULL;
}
}
return NULL;
}

View File

@@ -160,7 +160,7 @@ static void paging_handle_pending_requests(struct gsm_bts_paging_state *paging_b
} while (paging_bts->available_slots > 0
&& initial_request != current_request);
bsc_schedule_timer(&paging_bts->work_timer, 1, 0);
bsc_schedule_timer(&paging_bts->work_timer, 2, 0);
}
static void paging_worker(void *data)
@@ -245,7 +245,7 @@ static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr,
llist_add_tail(&req->entry, &bts_entry->pending_requests);
if (!bsc_timer_pending(&bts_entry->work_timer))
bsc_schedule_timer(&bts_entry->work_timer, 1, 0);
bsc_schedule_timer(&bts_entry->work_timer, 2, 0);
return 0;
}

View File

@@ -1198,6 +1198,17 @@ int sccp_connection_free(struct sccp_connection *connection)
return 0;
}
int sccp_connection_force_free(struct sccp_connection *con)
{
if (con->connection_state > SCCP_CONNECTION_STATE_NONE &&
con->connection_state < SCCP_CONNECTION_STATE_RELEASE_COMPLETE)
llist_del(&con->list);
con->connection_state = SCCP_CONNECTION_STATE_REFUSED;
sccp_connection_free(con);
return 0;
}
struct sccp_connection *sccp_connection_socket(void)
{
return talloc_zero(tall_sccp_ctx, struct sccp_connection);

View File

@@ -135,7 +135,7 @@ int gsm_silent_call_stop(struct gsm_subscriber *subscr)
if (!lchan->silent_call)
return -EINVAL;
put_lchan(lchan);
put_lchan(lchan, 0);
return 0;
}

View File

@@ -28,6 +28,7 @@
#include <openbsc/gsm_04_08.h>
#include <openbsc/mncc.h>
#include <openbsc/paging.h>
#include <openbsc/chan_alloc.h>
void *tall_trans_ctx;
@@ -95,14 +96,14 @@ void trans_free(struct gsm_trans *trans)
break;
}
if (trans->lchan)
put_lchan(trans->lchan);
if (!trans->lchan && trans->subscr && trans->subscr->net) {
/* Stop paging on all bts' */
paging_request_stop(NULL, trans->subscr, NULL);
}
if (trans->lchan)
put_lchan(trans->lchan, 0);
if (trans->subscr)
subscr_put(trans->subscr);
@@ -158,7 +159,7 @@ int trans_lchan_change(struct gsm_lchan *lchan_old,
llist_for_each_entry(trans, &net->trans_list, entry) {
if (trans->lchan == lchan_old) {
/* drop old channel use cound */
put_lchan(trans->lchan);
put_lchan(trans->lchan, 0);
/* assign new channel */
trans->lchan = lchan_new;
/* bump new channel use count */

View File

@@ -47,6 +47,7 @@ Boston, MA 02111-1307, USA. */
#include <openbsc/gsm_data.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/bsc_nat.h>
#include <osmocore/talloc.h>
void *tall_vty_cmd_ctx;
@@ -1949,6 +1950,13 @@ enum node_type vty_go_parent(struct vty *vty)
subscr_put(vty->index);
vty->index = NULL;
break;
case BSC_NODE:
vty->node = NAT_NODE;
{
struct bsc_config *bsc = vty->index;
vty->index = bsc->nat;
}
break;
default:
vty->node = CONFIG_NODE;
}
@@ -2362,6 +2370,18 @@ DEFUN(config_exit,
case VTY_NODE:
vty->node = CONFIG_NODE;
break;
case MGCP_NODE:
vty->node = CONFIG_NODE;
vty->index = NULL;
case NAT_NODE:
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
case BSC_NODE:
vty->node = NAT_NODE;
vty->index = NULL;
break;
default:
break;
}

View File

@@ -99,6 +99,7 @@ static void dump_pchan_load_vty(struct vty *vty, char *prefix,
static void net_dump_vty(struct vty *vty, struct gsm_network *net)
{
int i;
struct pchan_load pl;
vty_out(vty, "BSC is on Country Code %u, Network Code %u "
@@ -116,6 +117,8 @@ static void net_dump_vty(struct vty *vty, struct gsm_network *net)
VTY_NEWLINE);
vty_out(vty, " NECI (TCH/H): %u%s", net->neci,
VTY_NEWLINE);
vty_out(vty, " Use TCH for Paging any: %d%s", net->pag_any_tch,
VTY_NEWLINE);
vty_out(vty, " RRLP Mode: %s%s", rrlp_mode_name(net->rrlp.mode),
VTY_NEWLINE);
vty_out(vty, " MM Info: %s%s", net->send_mm_info ? "On" : "Off",
@@ -125,6 +128,12 @@ static void net_dump_vty(struct vty *vty, struct gsm_network *net)
network_chan_load(&pl, net);
vty_out(vty, " Current Channel Load:%s", VTY_NEWLINE);
dump_pchan_load_vty(vty, " ", &pl);
vty_out(vty, " Allowed Audio Codecs: ");
for (i = 0; i < net->audio_length; ++i)
vty_out(vty, "hr: %d ver: %d, ",
net->audio_support[i]->hr, net->audio_support[i]->ver);
vty_out(vty, "%s", VTY_NEWLINE);
}
DEFUN(show_net, show_net_cmd, "show network",
@@ -357,7 +366,11 @@ static int config_write_net(struct vty *vty)
{
vty_out(vty, "network%s", VTY_NEWLINE);
vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE);
if (gsmnet->core_country_code > 0)
vty_out(vty, " core network country code %u%s", gsmnet->core_country_code, VTY_NEWLINE);
vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE);
if (gsmnet->core_network_code > 0)
vty_out(vty, " core mobile network code %u%s", gsmnet->core_network_code, VTY_NEWLINE);
vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE);
vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE);
vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE);
@@ -365,6 +378,7 @@ static int config_write_net(struct vty *vty)
gsmnet->reject_cause, VTY_NEWLINE);
vty_out(vty, " encryption a5 %u%s", gsmnet->a5_encryption, VTY_NEWLINE);
vty_out(vty, " neci %u%s", gsmnet->neci, VTY_NEWLINE);
vty_out(vty, " paging any use tch %d%s", gsmnet->pag_any_tch, VTY_NEWLINE);
vty_out(vty, " rrlp mode %s%s", rrlp_mode_name(gsmnet->rrlp.mode),
VTY_NEWLINE);
vty_out(vty, " mm info %u%s", gsmnet->send_mm_info, VTY_NEWLINE);
@@ -392,6 +406,28 @@ static int config_write_net(struct vty *vty)
vty_out(vty, " timer t3117 %u%s", gsmnet->T3117, VTY_NEWLINE);
vty_out(vty, " timer t3119 %u%s", gsmnet->T3119, VTY_NEWLINE);
vty_out(vty, " timer t3141 %u%s", gsmnet->T3141, VTY_NEWLINE);
vty_out(vty, " ipacc rtp_payload %u%s", gsmnet->rtp_payload, VTY_NEWLINE);
vty_out(vty, " rtp base %u%s", gsmnet->rtp_base_port, VTY_NEWLINE);
if (gsmnet->audio_length != 0) {
int i;
vty_out(vty, " codec_list ");
for (i = 0; i < gsmnet->audio_length; ++i) {
printf("I... %d %d\n", i, gsmnet->audio_length);
if (i != 0)
vty_out(vty, ", ");
if (gsmnet->audio_support[i]->hr)
vty_out(vty, "hr%.1u", gsmnet->audio_support[i]->ver);
else
vty_out(vty, "fr%.1u", gsmnet->audio_support[i]->ver);
}
vty_out(vty, "%s", VTY_NEWLINE);
}
if (gsmnet->bsc_token)
vty_out(vty, " bsc_token %s%s", gsmnet->bsc_token, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -878,204 +914,6 @@ DEFUN(show_paging,
return CMD_SUCCESS;
}
static void _vty_output(struct debug_target *tgt, const char *line)
{
struct vty *vty = tgt->tgt_vty.vty;
vty_out(vty, "%s", line);
/* This is an ugly hack, but there is no easy way... */
if (strchr(line, '\n'))
vty_out(vty, "\r");
}
struct debug_target *debug_target_create_vty(struct vty *vty)
{
struct debug_target *target;
target = debug_target_create();
if (!target)
return NULL;
target->tgt_vty.vty = vty;
target->output = _vty_output;
return target;
}
DEFUN(enable_logging,
enable_logging_cmd,
"logging enable",
"Enables logging to this vty\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (conn->dbg) {
vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
conn->dbg = debug_target_create_vty(vty);
if (!conn->dbg)
return CMD_WARNING;
debug_add_target(conn->dbg);
return CMD_SUCCESS;
}
DEFUN(logging_fltr_imsi,
logging_fltr_imsi_cmd,
"logging filter imsi IMSI",
"Print all messages related to a IMSI\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_imsi_filter(conn->dbg, argv[0]);
return CMD_SUCCESS;
}
DEFUN(logging_fltr_all,
logging_fltr_all_cmd,
"logging filter all <0-1>",
"Print all messages to the console\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_all_filter(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
DEFUN(logging_use_clr,
logging_use_clr_cmd,
"logging color <0-1>",
"Use color for printing messages\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_use_color(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
DEFUN(logging_prnt_timestamp,
logging_prnt_timestamp_cmd,
"logging timestamp <0-1>",
"Print the timestamp of each message\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_print_timestamp(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
/* FIXME: those have to be kept in sync with the log levels and categories */
#define VTY_DEBUG_CATEGORIES "(rll|cc|mm|rr|rsl|nm|sms|pag|mncc|inp|mi|mib|mux|meas|sccp|msc|mgcp|ho|db|ref)"
#define VTY_DEBUG_LEVELS "(everything|debug|info|notice|error|fatal)"
DEFUN(logging_level,
logging_level_cmd,
"logging level " VTY_DEBUG_CATEGORIES " " VTY_DEBUG_LEVELS,
"Set the log level for a specified category\n")
{
struct telnet_connection *conn;
int category = debug_parse_category(argv[0]);
int level = debug_parse_level(argv[1]);
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (category < 0) {
vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (level < 0) {
vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE);
return CMD_WARNING;
}
conn->dbg->categories[category].enabled = 1;
conn->dbg->categories[category].loglevel = level;
return CMD_SUCCESS;
}
DEFUN(logging_set_category_mask,
logging_set_category_mask_cmd,
"logging set debug mask MASK",
"Decide which categories to output.\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_parse_category_mask(conn->dbg, argv[0]);
return CMD_SUCCESS;
}
DEFUN(logging_set_log_level,
logging_set_log_level_cmd,
"logging set log level <0-8>",
"Set the global log level. The value 0 implies no filtering.\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_log_level(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
DEFUN(diable_logging,
disable_logging_cmd,
"logging disable",
"Disables logging to this vty\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_del_target(conn->dbg);
talloc_free(conn->dbg);
conn->dbg = NULL;
return CMD_SUCCESS;
}
DEFUN(show_stats,
show_stats_cmd,
"show statistics",
@@ -1138,6 +976,16 @@ DEFUN(cfg_net_ncc,
return CMD_SUCCESS;
}
DEFUN(cfg_core_net_ncc,
cfg_core_net_ncc_cmd,
"core network country code <1-999>",
"Set the GSM country code to be used in the MSC connection")
{
gsmnet->core_country_code = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_mnc,
cfg_net_mnc_cmd,
"mobile network code <1-999>",
@@ -1148,6 +996,16 @@ DEFUN(cfg_net_mnc,
return CMD_SUCCESS;
}
DEFUN(cfg_core_net_mnc,
cfg_core_net_mnc_cmd,
"core mobile network code <1-999>",
"Set the GSM mobile network code to be used in the MSC connection")
{
gsmnet->core_network_code = atoi(argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_name_short,
cfg_net_name_short_cmd,
"short name NAME",
@@ -1212,6 +1070,7 @@ DEFUN(cfg_net_neci,
"Set if NECI of cell selection is to be set")
{
gsmnet->neci = atoi(argv[0]);
gsm_net_update_ctype(gsmnet);
return CMD_SUCCESS;
}
@@ -1298,6 +1157,112 @@ DEFUN(cfg_net_ho_max_distance, cfg_net_ho_max_distance_cmd,
return CMD_SUCCESS;
}
DEFUN(cfg_net_supported_codecs,
cfg_net_supported_codecs_cmd,
"codec_list .LIST",
"Set the three preferred audio codecs.\n"
"Codec List")
{
int saw_fr, saw_hr;
int i;
saw_fr = saw_hr = 0;
/* free the old list... if it exists */
if (gsmnet->audio_support) {
talloc_free(gsmnet->audio_support);
gsmnet->audio_support = NULL;
gsmnet->audio_length = 0;
}
/* create a new array */
gsmnet->audio_support =
talloc_zero_array(gsmnet, struct gsm_audio_support *, argc);
gsmnet->audio_length = argc;
for (i = 0; i < argc; ++i) {
/* check for hrX or frX */
if (strlen(argv[i]) != 3
|| argv[i][1] != 'r'
|| (argv[i][0] != 'h' && argv[i][0] != 'f')
|| argv[i][2] < 0x30
|| argv[i][2] > 0x39)
goto error;
gsmnet->audio_support[i] = talloc_zero(gsmnet->audio_support,
struct gsm_audio_support);
gsmnet->audio_support[i]->ver = atoi(argv[i] + 2);
if (strncmp("hr", argv[i], 2) == 0) {
gsmnet->audio_support[i]->hr = 1;
saw_hr = 1;
} else if (strncmp("fr", argv[i], 2) == 0) {
gsmnet->audio_support[i]->hr = 0;
saw_fr = 1;
}
if (saw_hr && saw_fr) {
vty_out(vty, "Can not have full-rate and half-rate codec.%s",
VTY_NEWLINE);
return CMD_ERR_INCOMPLETE;
}
}
return CMD_SUCCESS;
error:
vty_out(vty, "Codec name must be hrX or frX. Was '%s'%s",
argv[i], VTY_NEWLINE);
return CMD_ERR_INCOMPLETE;
}
DEFUN(cfg_net_ipacc_rtp_payload,
cfg_net_ipacc_rtp_payload_cmd,
"ipacc rtp_payload <0-256>",
"Override the RTP payload to use")
{
gsmnet->rtp_payload = atoi(argv[0]) & 0xff;
return CMD_SUCCESS;
}
DEFUN(cfg_net_rtp_base_port,
cfg_net_rtp_base_port_cmd,
"rtp base <0-65534>",
"Base port to use for MGCP RTP")
{
unsigned int port = atoi(argv[0]);
if (port > 65534) {
vty_out(vty, "%% wrong base port '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
gsmnet->rtp_base_port = port;
return CMD_SUCCESS;
}
DEFUN(cfg_net_bsc_token,
cfg_net_bsc_token_cmd,
"bsc_token TOKEN",
"A token for the BSC to be sent to the MSC")
{
if (gsmnet->bsc_token)
talloc_free(gsmnet->bsc_token);
gsmnet->bsc_token = talloc_strdup(gsmnet, argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_net_pag_any_tch,
cfg_net_pag_any_tch_cmd,
"paging any use tch (0|1)",
"Assign a TCH when receiving a Paging Any request")
{
gsmnet->pag_any_tch = atoi(argv[0]);
gsm_net_update_ctype(gsmnet);
return CMD_SUCCESS;
}
#define DECLARE_TIMER(number, doc) \
DEFUN(cfg_net_T##number, \
cfg_net_T##number##_cmd, \
@@ -1308,7 +1273,7 @@ DEFUN(cfg_net_ho_max_distance, cfg_net_ho_max_distance_cmd,
\
if (value < 0 || value > 65535) { \
vty_out(vty, "Timer value %s out of range.%s", \
argv[0], VTY_NEWLINE); \
argv[0], VTY_NEWLINE); \
return CMD_WARNING; \
} \
\
@@ -1328,7 +1293,6 @@ DECLARE_TIMER(3117, "Currently not used.")
DECLARE_TIMER(3119, "Currently not used.")
DECLARE_TIMER(3141, "Currently not used.")
/* per-BTS configuration */
DEFUN(cfg_bts,
cfg_bts_cmd,
@@ -1957,21 +1921,15 @@ int bsc_vty_init(struct gsm_network *net)
install_element(VIEW_NODE, &show_paging_cmd);
install_element(VIEW_NODE, &show_stats_cmd);
install_element(VIEW_NODE, &enable_logging_cmd);
install_element(VIEW_NODE, &disable_logging_cmd);
install_element(VIEW_NODE, &logging_fltr_imsi_cmd);
install_element(VIEW_NODE, &logging_fltr_all_cmd);
install_element(VIEW_NODE, &logging_use_clr_cmd);
install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
install_element(VIEW_NODE, &logging_set_category_mask_cmd);
install_element(VIEW_NODE, &logging_level_cmd);
install_element(VIEW_NODE, &logging_set_log_level_cmd);
openbsc_vty_add_cmds();
install_element(CONFIG_NODE, &cfg_net_cmd);
install_node(&net_node, config_write_net);
install_default(GSMNET_NODE);
install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
install_element(GSMNET_NODE, &cfg_core_net_ncc_cmd);
install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
install_element(GSMNET_NODE, &cfg_core_net_mnc_cmd);
install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
@@ -1987,6 +1945,9 @@ int bsc_vty_init(struct gsm_network *net)
install_element(GSMNET_NODE, &cfg_net_ho_pwr_interval_cmd);
install_element(GSMNET_NODE, &cfg_net_ho_pwr_hysteresis_cmd);
install_element(GSMNET_NODE, &cfg_net_ho_max_distance_cmd);
install_element(GSMNET_NODE, &cfg_net_supported_codecs_cmd);
install_element(GSMNET_NODE, &cfg_net_ipacc_rtp_payload_cmd);
install_element(GSMNET_NODE, &cfg_net_rtp_base_port_cmd);
install_element(GSMNET_NODE, &cfg_net_T3101_cmd);
install_element(GSMNET_NODE, &cfg_net_T3103_cmd);
install_element(GSMNET_NODE, &cfg_net_T3105_cmd);
@@ -1998,6 +1959,8 @@ int bsc_vty_init(struct gsm_network *net)
install_element(GSMNET_NODE, &cfg_net_T3117_cmd);
install_element(GSMNET_NODE, &cfg_net_T3119_cmd);
install_element(GSMNET_NODE, &cfg_net_T3141_cmd);
install_element(GSMNET_NODE, &cfg_net_bsc_token_cmd);
install_element(GSMNET_NODE, &cfg_net_pag_any_tch_cmd);
install_element(GSMNET_NODE, &cfg_bts_cmd);
install_node(&bts_node, config_write_bts);

View File

@@ -0,0 +1,48 @@
/* OpenBSC interface to quagga VTY - BSC options */
/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <vty/command.h>
#include <vty/buffer.h>
#include <vty/vty.h>
#include <openbsc/gsm_data.h>
static struct gsmnet *gsmnet = NULL;
DEFUN(show_bsc, show_bsc_cmd, "show bsc",
SHOW_STR "Display information about the BSC\n")
{
vty_out(vty, "BSC... not implemented yet%s", VTY_NEWLINE);
return CMD_SUCCESS;
}
int bsc_vty_init_extra(struct gsm_network *net)
{
gsmnet = net;
/* get runtime information */
install_element(VIEW_NODE, &show_bsc_cmd);
return 0;
}

View File

@@ -0,0 +1,244 @@
/* OpenBSC logging helper for the VTY */
/* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
* (C) 2009-2010 by Holger Hans Peter Freyther
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <openbsc/vty.h>
#include <openbsc/telnet_interface.h>
#include <osmocore/talloc.h>
#include <vty/command.h>
#include <vty/buffer.h>
#include <vty/vty.h>
#include <stdlib.h>
static void _vty_output(struct debug_target *tgt, const char *line)
{
struct vty *vty = tgt->tgt_vty.vty;
vty_out(vty, "%s", line);
/* This is an ugly hack, but there is no easy way... */
if (strchr(line, '\n'))
vty_out(vty, "\r");
}
struct debug_target *debug_target_create_vty(struct vty *vty)
{
struct debug_target *target;
target = debug_target_create();
if (!target)
return NULL;
target->tgt_vty.vty = vty;
target->output = _vty_output;
return target;
}
DEFUN(enable_logging,
enable_logging_cmd,
"logging enable",
"Enables logging to this vty\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (conn->dbg) {
vty_out(vty, "Logging already enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
conn->dbg = debug_target_create_vty(vty);
if (!conn->dbg)
return CMD_WARNING;
debug_add_target(conn->dbg);
return CMD_SUCCESS;
}
DEFUN(logging_fltr_imsi,
logging_fltr_imsi_cmd,
"logging filter imsi IMSI",
"Print all messages related to a IMSI\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_imsi_filter(conn->dbg, argv[0]);
return CMD_SUCCESS;
}
DEFUN(logging_fltr_all,
logging_fltr_all_cmd,
"logging filter all <0-1>",
"Print all messages to the console\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_all_filter(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
DEFUN(logging_use_clr,
logging_use_clr_cmd,
"logging color <0-1>",
"Use color for printing messages\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_use_color(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
DEFUN(logging_prnt_timestamp,
logging_prnt_timestamp_cmd,
"logging timestamp <0-1>",
"Print the timestamp of each message\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_print_timestamp(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
/* FIXME: those have to be kept in sync with the log levels and categories */
#define VTY_DEBUG_CATEGORIES "(rll|cc|mm|rr|rsl|nm|sms|pag|mncc|inp|mi|mib|mux|meas|sccp|msc|mgcp|ho|db|ref|nat)"
#define VTY_DEBUG_LEVELS "(everything|debug|info|notice|error|fatal)"
DEFUN(logging_level,
logging_level_cmd,
"logging level " VTY_DEBUG_CATEGORIES " " VTY_DEBUG_LEVELS,
"Set the log level for a specified category\n")
{
struct telnet_connection *conn;
int category = debug_parse_category(argv[0]);
int level = debug_parse_level(argv[1]);
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (category < 0) {
vty_out(vty, "Invalid category `%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (level < 0) {
vty_out(vty, "Invalid level `%s'%s", argv[1], VTY_NEWLINE);
return CMD_WARNING;
}
conn->dbg->categories[category].enabled = 1;
conn->dbg->categories[category].loglevel = level;
return CMD_SUCCESS;
}
DEFUN(logging_set_category_mask,
logging_set_category_mask_cmd,
"logging set debug mask MASK",
"Decide which categories to output.\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_parse_category_mask(conn->dbg, argv[0]);
return CMD_SUCCESS;
}
DEFUN(logging_set_log_level,
logging_set_log_level_cmd,
"logging set log level <0-8>",
"Set the global log level. The value 0 implies no filtering.\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_set_log_level(conn->dbg, atoi(argv[0]));
return CMD_SUCCESS;
}
DEFUN(diable_logging,
disable_logging_cmd,
"logging disable",
"Disables logging to this vty\n")
{
struct telnet_connection *conn;
conn = (struct telnet_connection *) vty->priv;
if (!conn->dbg) {
vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
return CMD_WARNING;
}
debug_del_target(conn->dbg);
talloc_free(conn->dbg);
conn->dbg = NULL;
return CMD_SUCCESS;
}
void openbsc_vty_add_cmds()
{
install_element(VIEW_NODE, &enable_logging_cmd);
install_element(VIEW_NODE, &disable_logging_cmd);
install_element(VIEW_NODE, &logging_fltr_imsi_cmd);
install_element(VIEW_NODE, &logging_fltr_all_cmd);
install_element(VIEW_NODE, &logging_use_clr_cmd);
install_element(VIEW_NODE, &logging_prnt_timestamp_cmd);
install_element(VIEW_NODE, &logging_set_category_mask_cmd);
install_element(VIEW_NODE, &logging_level_cmd);
install_element(VIEW_NODE, &logging_set_log_level_cmd);
}

View File

@@ -1 +1 @@
SUBDIRS = debug gsm0408 db channel sccp
SUBDIRS = debug gsm0408 db channel sccp bsc-nat

View File

@@ -0,0 +1,17 @@
INCLUDES = $(all_includes) -I$(top_srcdir)/include
AM_CFLAGS=-Wall -ggdb3 $(LIBOSMOCORE_CFLAGS)
EXTRA_DIST = bsc_data.c
noinst_PROGRAMS = bsc_nat_test
bsc_nat_test_SOURCES = bsc_nat_test.c \
$(top_srcdir)/src/nat/bsc_filter.c \
$(top_srcdir)/src/nat/bsc_sccp.c \
$(top_srcdir)/src/nat/bsc_nat_utils.c \
$(top_srcdir)/src/nat/bsc_mgcp_utils.c \
$(top_srcdir)/src/mgcp/mgcp_protocol.c \
$(top_srcdir)/src/mgcp/mgcp_network.c \
$(top_srcdir)/src/bssap.c
bsc_nat_test_LDADD = $(top_builddir)/src/libbsc.a $(top_builddir)/src/libsccp.a $(LIBOSMOCORE_LIBS)

View File

@@ -0,0 +1,154 @@
/* test data */
/* BSC -> MSC, CR */
static const u_int8_t bsc_cr[] = {
0x00, 0x2e, 0xfd,
0x01, 0x00, 0x00, 0x15, 0x02, 0x02, 0x04, 0x02,
0x42, 0xfe, 0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05,
0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x1c, 0xc3,
0x51, 0x17, 0x12, 0x05, 0x08, 0x20, 0x72, 0xf4,
0x90, 0x20, 0x1d, 0x50, 0x08, 0x29, 0x47, 0x80,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00 };
static const u_int8_t bsc_cr_patched[] = {
0x00, 0x2e, 0xfd,
0x01, 0x00, 0x00, 0x05, 0x02, 0x02, 0x04, 0x02,
0x42, 0xfe, 0x0f, 0x21, 0x00, 0x1f, 0x57, 0x05,
0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x1c, 0xc3,
0x51, 0x17, 0x12, 0x05, 0x08, 0x20, 0x72, 0xf4,
0x90, 0x20, 0x1d, 0x50, 0x08, 0x29, 0x47, 0x80,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00 };
/* CC, MSC -> BSC */
static const u_int8_t msc_cc[] = {
0x00, 0x0a, 0xfd,
0x02, 0x00, 0x00, 0x05, 0x01, 0x1f, 0xe4, 0x02,
0x01, 0x00 };
static const u_int8_t msc_cc_patched[] = {
0x00, 0x0a, 0xfd,
0x02, 0x00, 0x00, 0x15, 0x01, 0x1f, 0xe4, 0x02,
0x01, 0x00 };
/* Classmark, BSC -> MSC */
static const u_int8_t bsc_dtap[] = {
0x00, 0x17, 0xfd,
0x06, 0x01, 0x1f, 0xe4, 0x00, 0x01, 0x10, 0x00,
0x0e, 0x54, 0x12, 0x03, 0x50, 0x18, 0x93, 0x13,
0x06, 0x60, 0x14, 0x45, 0x00, 0x81, 0x00 };
static const u_int8_t bsc_dtap_patched[] = {
0x00, 0x17, 0xfd,
0x06, 0x01, 0x1f, 0xe4, 0x00, 0x01, 0x10, 0x00,
0x0e, 0x54, 0x12, 0x03, 0x50, 0x18, 0x93, 0x13,
0x06, 0x60, 0x14, 0x45, 0x00, 0x81, 0x00 };
/* Clear command, MSC -> BSC */
static const u_int8_t msc_dtap[] = {
0x00, 0x0d, 0xfd,
0x06, 0x00, 0x00, 0x05, 0x00, 0x01, 0x06, 0x00,
0x04, 0x20, 0x04, 0x01, 0x09 };
static const u_int8_t msc_dtap_patched[] = {
0x00, 0x0d, 0xfd,
0x06, 0x00, 0x00, 0x15, 0x00, 0x01, 0x06, 0x00,
0x04, 0x20, 0x04, 0x01, 0x09 };
/*RLSD, MSC -> BSC */
static const u_int8_t msc_rlsd[] = {
0x00, 0x0a, 0xfd,
0x04, 0x00, 0x00, 0x05, 0x01, 0x1f, 0xe4, 0x00,
0x01, 0x00 };
static const u_int8_t msc_rlsd_patched[] = {
0x00, 0x0a, 0xfd,
0x04, 0x00, 0x00, 0x15, 0x01, 0x1f, 0xe4, 0x00,
0x01, 0x00 };
/* RLC, BSC -> MSC */
static const u_int8_t bsc_rlc[] = {
0x00, 0x07, 0xfd,
0x05, 0x01, 0x1f, 0xe4, 0x00, 0x00, 0x15 };
static const u_int8_t bsc_rlc_patched[] = {
0x00, 0x07, 0xfd,
0x05, 0x01, 0x1f, 0xe4, 0x00, 0x00, 0x05 };
/* a paging command */
static const u_int8_t paging_by_lac_cmd[] = {
0x00, 0x22, 0xfd, 0x09,
0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x02, 0x00,
0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x12, 0x00,
0x10, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10, 0x02,
0x01, 0x50, 0x02, 0x30, 0x1a, 0x03, 0x05, 0x20,
0x15 };
/* an assignment command */
static const u_int8_t ass_cmd[] = {
0x00, 0x12, 0xfd, 0x06,
0x00, 0x00, 0x49, 0x00, 0x01, 0x0b, 0x00, 0x09,
0x01, 0x0b, 0x03, 0x01, 0x0a, 0x11, 0x01, 0x00,
0x15 };
/*
* MGCP messages
*/
/* nothing to patch */
static const char crcx[] = "CRCX 23265295 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n";
static const char crcx_patched[] = "CRCX 23265295 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n";
/* patch the ip and port */
static const char crcx_resp[] = "200 23265295\r\nI: 1\r\n\r\nv=0\r\nc=IN IP4 172.16.18.2\r\nm=audio 4002 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
static const char crcx_resp_patched[] = "200 23265295\r\nI: 1\r\n\r\nv=0\r\nc=IN IP4 10.0.0.1\r\nm=audio 999 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
/* patch the ip and port */
static const char mdcx[] = " MDCX 23330829 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nI: 1\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n\r\nv=0\r\no=- 1049380491 0 IN IP4 172.16.18.2\r\ns=-\r\nc=IN IP4 172.16.18.2\r\nt=0 0\r\nm=audio 4410 RTP/AVP 126\r\na=rtpmap:126 AMR/8000/1\r\na=fmtp:126 mode-set=2;start-mode=0\r\na=ptime:20\r\na=recvonly\r\nm=image 4412 udptl t38\r\na=T38FaxVersion:0\r\na=T38MaxBitRate:14400\r\n";
static const char mdcx_patched[] = " MDCX 23330829 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nI: 1\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n\r\nv=0\r\no=- 1049380491 0 IN IP4 172.16.18.2\r\ns=-\r\nc=IN IP4 10.0.0.23\r\nt=0 0\r\nm=audio 6666 RTP/AVP 126\r\na=rtpmap:126 AMR/8000/1\r\na=fmtp:126 mode-set=2;start-mode=0\r\na=ptime:20\r\na=recvonly\r\nm=image 4412 udptl t38\r\na=T38FaxVersion:0\r\na=T38MaxBitRate:14400\r\n";
static const char mdcx_resp[] = "200 23330829\r\n\r\nv=0\r\nc=IN IP4 172.16.18.2\r\nm=audio 4002 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
static const char mdcx_resp_patched[] = "200 23330829\r\n\r\nv=0\r\nc=IN IP4 10.0.0.23\r\nm=audio 5555 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n";
/* different line ending */
static const char mdcx_resp2[] = "200 33330829\n\nv=0\nc=IN IP4 172.16.18.2\nm=audio 4002 RTP/AVP 98\na=rtpmap:98 AMR/8000\n";
static const char mdcx_resp_patched2[] = "200 33330829\n\nv=0\nc=IN IP4 10.0.0.23\nm=audio 5555 RTP/AVP 98\na=rtpmap:98 AMR/8000\n";
struct mgcp_patch_test {
const char *orig;
const char *patch;
const char *ip;
const int port;
};
static const struct mgcp_patch_test mgcp_messages[] = {
{
.orig = crcx,
.patch = crcx_patched,
.ip = "0.0.0.0",
.port = 2323,
},
{
.orig = crcx_resp,
.patch = crcx_resp_patched,
.ip = "10.0.0.1",
.port = 999,
},
{
.orig = mdcx,
.patch = mdcx_patched,
.ip = "10.0.0.23",
.port = 6666,
},
{
.orig = mdcx_resp,
.patch = mdcx_resp_patched,
.ip = "10.0.0.23",
.port = 5555,
},
{
.orig = mdcx_resp2,
.patch = mdcx_resp_patched2,
.ip = "10.0.0.23",
.port = 5555,
},
};

View File

@@ -0,0 +1,538 @@
/*
* BSC NAT Message filtering
*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2010 by On-Waves
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <openbsc/debug.h>
#include <openbsc/gsm_data.h>
#include <openbsc/bsc_nat.h>
#include <osmocore/talloc.h>
#include <stdio.h>
/* test messages for ipa */
static u_int8_t ipa_id[] = {
0x00, 0x01, 0xfe, 0x06,
};
/* SCCP messages are below */
static u_int8_t gsm_reset[] = {
0x00, 0x12, 0xfd,
0x09, 0x00, 0x03, 0x05, 0x07, 0x02, 0x42, 0xfe,
0x02, 0x42, 0xfe, 0x06, 0x00, 0x04, 0x30, 0x04,
0x01, 0x20,
};
static const u_int8_t gsm_reset_ack[] = {
0x00, 0x13, 0xfd,
0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x03,
0x00, 0x01, 0x31,
};
static const u_int8_t gsm_paging[] = {
0x00, 0x20, 0xfd,
0x09, 0x00, 0x03, 0x07, 0x0b, 0x04, 0x43, 0x01,
0x00, 0xfe, 0x04, 0x43, 0x5c, 0x00, 0xfe, 0x10,
0x00, 0x0e, 0x52, 0x08, 0x08, 0x29, 0x47, 0x10,
0x02, 0x01, 0x31, 0x97, 0x61, 0x1a, 0x01, 0x06,
};
/* BSC -> MSC connection open */
static const u_int8_t bssmap_cr[] = {
0x00, 0x2c, 0xfd,
0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x04, 0x02,
0x42, 0xfe, 0x0f, 0x1f, 0x00, 0x1d, 0x57, 0x05,
0x08, 0x00, 0x72, 0xf4, 0x80, 0x20, 0x12, 0xc3,
0x50, 0x17, 0x10, 0x05, 0x24, 0x11, 0x03, 0x33,
0x19, 0xa2, 0x08, 0x29, 0x47, 0x10, 0x02, 0x01,
0x31, 0x97, 0x61, 0x00
};
/* MSC -> BSC connection confirm */
static const u_int8_t bssmap_cc[] = {
0x00, 0x0a, 0xfd,
0x02, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
};
/* MSC -> BSC released */
static const u_int8_t bssmap_released[] = {
0x00, 0x0e, 0xfd,
0x04, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x00, 0x01, 0x0f,
0x02, 0x23, 0x42, 0x00,
};
/* BSC -> MSC released */
static const u_int8_t bssmap_release_complete[] = {
0x00, 0x07, 0xfd,
0x05, 0x01, 0x02, 0x03, 0x00, 0x00, 0x03
};
/* both directions IT timer */
static const u_int8_t connnection_it[] = {
0x00, 0x0b, 0xfd,
0x10, 0x01, 0x02, 0x03, 0x01, 0x02, 0x03,
0x00, 0x00, 0x00, 0x00,
};
/* MGCP wrap... */
static const u_int8_t mgcp_msg[] = {
0x00, 0x03, 0xfc,
0x20, 0x20, 0x20,
};
struct filter_result {
const u_int8_t *data;
const u_int16_t length;
const int dir;
const int result;
};
static const struct filter_result results[] = {
{
.data = ipa_id,
.length = ARRAY_SIZE(ipa_id),
.dir = DIR_MSC,
.result = 1,
},
{
.data = gsm_reset,
.length = ARRAY_SIZE(gsm_reset),
.dir = DIR_MSC,
.result = 1,
},
{
.data = gsm_reset_ack,
.length = ARRAY_SIZE(gsm_reset_ack),
.dir = DIR_BSC,
.result = 1,
},
{
.data = gsm_paging,
.length = ARRAY_SIZE(gsm_paging),
.dir = DIR_BSC,
.result = 0,
},
{
.data = bssmap_cr,
.length = ARRAY_SIZE(bssmap_cr),
.dir = DIR_MSC,
.result = 0,
},
{
.data = bssmap_cc,
.length = ARRAY_SIZE(bssmap_cc),
.dir = DIR_BSC,
.result = 0,
},
{
.data = bssmap_released,
.length = ARRAY_SIZE(bssmap_released),
.dir = DIR_MSC,
.result = 0,
},
{
.data = bssmap_release_complete,
.length = ARRAY_SIZE(bssmap_release_complete),
.dir = DIR_BSC,
.result = 0,
},
{
.data = mgcp_msg,
.length = ARRAY_SIZE(mgcp_msg),
.dir = DIR_MSC,
.result = 0,
},
{
.data = connnection_it,
.length = ARRAY_SIZE(connnection_it),
.dir = DIR_BSC,
.result = 0,
},
{
.data = connnection_it,
.length = ARRAY_SIZE(connnection_it),
.dir = DIR_MSC,
.result = 0,
},
};
static void test_filter(void)
{
int i;
/* start testinh with proper messages */
fprintf(stderr, "Testing BSS Filtering.\n");
for (i = 0; i < ARRAY_SIZE(results); ++i) {
int result;
struct bsc_nat_parsed *parsed;
struct msgb *msg = msgb_alloc(4096, "test-message");
fprintf(stderr, "Going to test item: %d\n", i);
memcpy(msg->data, results[i].data, results[i].length);
msg->l2h = msgb_put(msg, results[i].length);
parsed = bsc_nat_parse(msg);
if (!parsed) {
fprintf(stderr, "FAIL: Failed to parse the message\n");
continue;
}
result = bsc_nat_filter_ipa(results[i].dir, msg, parsed);
if (result != results[i].result) {
fprintf(stderr, "FAIL: Not the expected result got: %d wanted: %d\n",
result, results[i].result);
}
msgb_free(msg);
}
}
#include "bsc_data.c"
static void copy_to_msg(struct msgb *msg, const u_int8_t *data, unsigned int length)
{
msgb_reset(msg);
msg->l2h = msgb_put(msg, length);
memcpy(msg->l2h, data, msgb_l2len(msg));
}
#define VERIFY(con_found, con, msg, ver, str) \
if (!con_found || con_found->bsc != con) { \
fprintf(stderr, "Failed to find the con: %p\n", con_found); \
abort(); \
} \
if (memcmp(msg->data, ver, sizeof(ver)) != 0) { \
fprintf(stderr, "Failed to patch the %s msg.\n", str); \
abort(); \
}
/* test conn tracking once */
static void test_contrack()
{
int rc;
struct bsc_nat *nat;
struct bsc_connection *con;
struct sccp_connections *con_found;
struct bsc_nat_parsed *parsed;
struct msgb *msg;
fprintf(stderr, "Testing connection tracking.\n");
nat = bsc_nat_alloc();
con = bsc_connection_alloc(nat);
msg = msgb_alloc(4096, "test");
/* 1.) create a connection */
copy_to_msg(msg, bsc_cr, sizeof(bsc_cr));
parsed = bsc_nat_parse(msg);
con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
if (con_found != NULL) {
fprintf(stderr, "Con should not exist %p\n", con_found);
abort();
}
rc = create_sccp_src_ref(con, msg, parsed);
if (rc != 0) {
fprintf(stderr, "Failed to create a ref\n");
abort();
}
con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
if (!con_found || con_found->bsc != con) {
fprintf(stderr, "Failed to find the con: %p\n", con_found);
abort();
}
if (memcmp(msg->data, bsc_cr_patched, sizeof(bsc_cr_patched)) != 0) {
fprintf(stderr, "Failed to patch the BSC CR msg.\n");
abort();
}
talloc_free(parsed);
/* 2.) get the cc */
copy_to_msg(msg, msc_cc, sizeof(msc_cc));
parsed = bsc_nat_parse(msg);
con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
VERIFY(con_found, con, msg, msc_cc_patched, "MSC CC");
if (update_sccp_src_ref(con_found, parsed) != 0) {
fprintf(stderr, "Failed to update the SCCP con.\n");
abort();
}
/* 3.) send some data */
copy_to_msg(msg, bsc_dtap, sizeof(bsc_dtap));
parsed = bsc_nat_parse(msg);
con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
VERIFY(con_found, con, msg, bsc_dtap_patched, "BSC DTAP");
/* 4.) receive some data */
copy_to_msg(msg, msc_dtap, sizeof(msc_dtap));
parsed = bsc_nat_parse(msg);
con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
VERIFY(con_found, con, msg, msc_dtap_patched, "MSC DTAP");
/* 5.) close the connection */
copy_to_msg(msg, msc_rlsd, sizeof(msc_rlsd));
parsed = bsc_nat_parse(msg);
con_found = patch_sccp_src_ref_to_bsc(msg, parsed, nat);
VERIFY(con_found, con, msg, msc_rlsd_patched, "MSC RLSD");
/* 6.) confirm the connection close */
copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
parsed = bsc_nat_parse(msg);
con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
if (!con_found || con_found->bsc != con) {
fprintf(stderr, "Failed to find the con: %p\n", con_found);
abort();
}
if (memcmp(msg->data, bsc_rlc_patched, sizeof(bsc_rlc_patched)) != 0) {
fprintf(stderr, "Failed to patch the BSC CR msg.\n");
abort();
}
remove_sccp_src_ref(con, msg, parsed);
talloc_free(parsed);
copy_to_msg(msg, bsc_rlc, sizeof(bsc_rlc));
parsed = bsc_nat_parse(msg);
con_found = patch_sccp_src_ref_to_msc(msg, parsed, nat);
/* verify that it is gone */
if (con_found != NULL) {
fprintf(stderr, "Con should be gone. %p\n", con_found);
abort();
}
talloc_free(parsed);
talloc_free(nat);
msgb_free(msg);
}
static void test_paging(void)
{
struct bsc_nat *nat;
struct bsc_connection *con;
struct bsc_nat_parsed *parsed;
struct bsc_config cfg;
struct msgb *msg;
fprintf(stderr, "Testing paging by lac.\n");
nat = bsc_nat_alloc();
con = bsc_connection_alloc(nat);
con->cfg = &cfg;
cfg.lac = 23;
con->authenticated = 1;
llist_add(&con->list_entry, &nat->bsc_connections);
msg = msgb_alloc(4096, "test");
/* Test completely bad input */
copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
if (bsc_nat_find_bsc(nat, msg) != 0) {
fprintf(stderr, "Should have not found anything.\n");
abort();
}
/* Test it by not finding it */
copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
parsed = bsc_nat_parse(msg);
if (bsc_nat_find_bsc(nat, msg) != 0) {
fprintf(stderr, "Should have not found aynthing.\n");
abort();
}
talloc_free(parsed);
/* Test by finding it */
cfg.lac = 8213;
copy_to_msg(msg, paging_by_lac_cmd, sizeof(paging_by_lac_cmd));
parsed = bsc_nat_parse(msg);
if (bsc_nat_find_bsc(nat, msg) != con) {
fprintf(stderr, "Should have found it.\n");
abort();
}
talloc_free(parsed);
}
static void test_mgcp_ass_tracking(void)
{
struct sccp_connections con;
struct bsc_nat_parsed *parsed;
struct msgb *msg;
fprintf(stderr, "Testing MGCP.\n");
memset(&con, 0, sizeof(con));
msg = msgb_alloc(4096, "foo");
copy_to_msg(msg, ass_cmd, sizeof(ass_cmd));
parsed = bsc_nat_parse(msg);
if (bsc_mgcp_assign(&con, msg) != 0) {
fprintf(stderr, "Failed to handle assignment.\n");
abort();
}
if (con.msc_timeslot != 21) {
fprintf(stderr, "Timeslot should be 21.\n");
abort();
}
if (con.bsc_timeslot != 21) {
fprintf(stderr, "Assigned timeslot should have been 21.\n");
abort();
}
talloc_free(parsed);
bsc_mgcp_clear(&con);
if (con.bsc_timeslot != -1 || con.msc_timeslot != -1) {
fprintf(stderr, "Clearing should remove the mapping.\n");
abort();
}
}
/* test the code to find a given connection */
static void test_mgcp_find(void)
{
struct bsc_nat *nat;
struct bsc_connection *con;
struct sccp_connections *sccp_con;
fprintf(stderr, "Testing finding of a BSC Connection\n");
nat = bsc_nat_alloc();
con = bsc_connection_alloc(nat);
llist_add(&con->list_entry, &nat->bsc_connections);
sccp_con = talloc_zero(con, struct sccp_connections);
sccp_con->msc_timeslot = 12;
sccp_con->bsc_timeslot = 12;
sccp_con->bsc = con;
llist_add(&sccp_con->list_entry, &nat->sccp_connections);
if (bsc_mgcp_find_con(nat, 11) != NULL) {
fprintf(stderr, "Found the wrong connection.\n");
abort();
}
if (bsc_mgcp_find_con(nat, 12) != con) {
fprintf(stderr, "Didn't find the connection\n");
abort();
}
sccp_con->msc_timeslot = 0;
sccp_con->bsc_timeslot = 0;
if (bsc_mgcp_find_con(nat, 1) != con) {
fprintf(stderr, "Didn't find the connection\n");
abort();
}
/* free everything */
talloc_free(nat);
}
static void test_mgcp_rewrite(void)
{
int i;
struct msgb *output;
fprintf(stderr, "Test rewriting MGCP messages.\n");
for (i = 0; i < ARRAY_SIZE(mgcp_messages); ++i) {
const char *orig = mgcp_messages[i].orig;
const char *patc = mgcp_messages[i].patch;
const char *ip = mgcp_messages[i].ip;
const int port = mgcp_messages[i].port;
char *input = strdup(orig);
output = bsc_mgcp_rewrite(input, strlen(input), ip, port);
if (msgb_l2len(output) != strlen(patc)) {
fprintf(stderr, "Wrong sizes for test: %d %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig));
fprintf(stderr, "String '%s' vs '%s'\n", (const char *) output->l2h, patc);
abort();
}
if (memcmp(output->l2h, patc, msgb_l2len(output)) != 0) {
fprintf(stderr, "Broken on %d msg: '%s'\n", i, (const char *) output->l2h);
abort();
}
msgb_free(output);
free(input);
}
}
static void test_mgcp_parse(void)
{
int code, ci;
char transaction[60];
fprintf(stderr, "Test MGCP response parsing.\n");
if (bsc_mgcp_parse_response(crcx_resp, &code, transaction) != 0) {
fprintf(stderr, "Failed to parse CRCX resp.\n");
abort();
}
if (code != 200) {
fprintf(stderr, "Failed to parse the CODE properly. Got: %d\n", code);
abort();
}
if (strcmp(transaction, "23265295") != 0) {
fprintf(stderr, "Failed to parse transaction id: '%s'\n", transaction);
abort();
}
ci = bsc_mgcp_extract_ci(crcx_resp);
if (ci != 1) {
fprintf(stderr, "Failed to parse the CI. Got: %d\n", ci);
abort();
}
}
int main(int argc, char **argv)
{
struct debug_target *stderr_target;
stderr_target = debug_target_create_stderr();
debug_add_target(stderr_target);
debug_set_all_filter(stderr_target, 1);
test_filter();
test_contrack();
test_paging();
test_mgcp_ass_tracking();
test_mgcp_find();
test_mgcp_rewrite();
test_mgcp_parse();
return 0;
}
void input_event()
{}
int nm_state_event()
{
return -1;
}
int gsm0408_rcvmsg(struct msgb *msg, u_int8_t link_id)
{
return -1;
}

View File

@@ -76,6 +76,8 @@ int main(int argc, char** argv)
void nm_state_event() {}
void input_event() {}
void sms_alloc() {}
void _lchan_release() {}
void gsm_net_update_ctype(struct gsm_network *network) {}
struct tlv_definition nm_att_tlvdef;