Commit Graph

79 Commits

Author SHA1 Message Date
Neels Hofmeyr 535df15bc5 vty: install default commands for SIP,MNCC,APP_NODE
Change-Id: Iee51881cc07d56209647fb4f505f8f6be6b885f0
2017-09-19 03:30:03 +02:00
Keith Whyte b603272787 sdp.c Send octet-align in fmtp
rfc4867 8.2:

      octet-align: Permissible values are 0 and 1.  If 1, octet-aligned
               operation SHALL be used.  If 0 or if not present,
               bandwidth-efficient operation is employed.

We don't have any support for AMR BE mode, but if we don't
send this the other end expects BE mode and can't decode the stream

Change-Id: I938758ac4ec55db9223e3da6c3c277e8fa670055
2017-09-03 18:30:53 +00:00
Holger Hans Peter Freyther 417f254216 mncc/sip: Attempt to parse the media from session in progress
Parse the media from session in progress and if present in alerting
connect the call early. Sadly this sets RTP to the sendrecv mode even
if we would like to keep it as recvonly.

Change-Id: I98d173abc46c67b87666ed2f193a581d6e72344b
Related: OS#1784
2017-03-23 09:01:45 +00:00
Holger Hans Peter Freyther 9d796ff156 mncc: Enable in-band signalling for early media
Besides sending the alerting request we should inform the
MS that there is in-band information now. We do not seem
to export these flags in protocol/gsm_04_08.h so hardcode
them for now (until I come up with good names for them).

Related: OS#1784

Change-Id: I80b1e1f4ca045bd63536476702a5812f27d9b36d
2017-03-23 09:01:14 +00:00
Holger Hans Peter Freyther 4649746798 dtmf: Forward DTMF from MNCC to SIP
We are not using the RTP telephony-event here but the older dtmf
relay. We also only have a fixed DTMF duration for now.

Change-Id: Icf770fae89f7aedf6eba9a119db9b8acc7f938df
2017-03-23 09:00:24 +00:00
Holger Hans Peter Freyther 3d9ae085bf sip: Actually honor the remote port of the pbx
So far the remote_port has never been used. sofia-sip did the right
thing and put the port into the "Contact" and the rport option for
the via. But we would have never been able to connect a PBX on a
different port (as sofia-sip seems to parse the destination from the
to address).

Change-Id: Ifbd49b4aa6b01b118fe67e39dddef50b2946159c
2017-03-23 07:32:04 +00:00
Holger Hans Peter Freyther 62f50f5297 dtmf: Start handling the DTMF MNCC messages and respond
Simply respond to the dtmf start/stop with a response
and move on.

Change-Id: Iffc92ea2112c9943ce89c244a9b323125c352ae5
2017-03-23 07:30:17 +00:00
Holger Hans Peter Freyther 37c2254f5d evpoll: Add workaround for usage of IP_RECVERR in sofia-sip
We are using glib to benefit from the sofia-sip-glib eventloop
integration and set a poll func (evpoll) to be called by glib
to integrate with the rest of libosmocore.

Sofia-sip will use IP_RECVERR to enable error reporting on the
socket and then sets SU_WAIT_ERR (mapped to POLLERR if not using
kqueue) in the internal events flag of the socket. This will
be registered with a su_wait (mapped to struct pollfd) and then
glib will be called with g_source_add_poll. At this point the
the fd->events will still have the POLLERR bit set.

Before glib is calling its internal poll routine or our one
it will copy all registered fd into an array and mask the
events flags:

      /* In direct contradiction to the Unix98 spec, IRIX runs into
       * difficulty if you pass in POLLERR, POLLHUP or POLLNVAL
       * flags in the events field of the pollfd while it should
       * just ignoring them. So we mask them out here.
       */
      events = pollrec->fd->events & ~(G_IO_ERR|G_IO_HUP|G_IO_NVAL);

This leads to the POLLERR flag never been set in the revents
of the struct poll_fd and as such we never put them in the
exceptionset and as such:

	static int tport_base_wakeup(tport_t *self, int events)
	{
  	int error = 0;

  	if (events & SU_WAIT_ERR)
    		error = tport_error_event(self);

tport_base_wakeup will never call tport_error_event. And the error
will be stuck in the socket data forever and recvmsg will return
a zero length packet. And this will repeat until the end of time.

As a first hack I mapped SU_WAIT_ERR to POLLPRI but when using
select the Linux kernel will not put the socket error into the
except queue unless the sockopt SOCK_SELECT_ERR_QUEUE is used.

One option is to use poll and then map the select requirements
to poll. Right now I just signal POLLERR as well to trigger
tport_error_event. This will result in extra syscalls for each
received UDP message right now.

Change-Id: I5bec4a7b70f421ab670e649e5bc1ea6faf59707c
2017-03-08 10:32:13 +01:00
Holger Hans Peter Freyther 49880ddf74 mncc: Fix use after free on mncc socket disconnection
When the MNCC socket breaks down we would release all callds but when
there is no remote call the call would be released before

	if (call->remote)
		...

is being executed leading to a use after free. Fix it by copying the
legs first and assuming the call will be gone after that.

==3618== Invalid read of size 4
==3618==    at 0x804A18A: app_mncc_disconnected (app.c:49)
==3618==    by 0x804B52D: close_connection (mncc.c:255)
==3618==    by 0x804BCFA: mncc_rtp_send.constprop.13 (mncc.c:145)
==3618==    by 0x804CC86: check_setup (mncc.c:435)
==3618==    by 0x804CC86: mncc_data (mncc.c:795)
==3618==    by 0x42FCF94: osmo_fd_disp_fds (select.c:167)
==3618==    by 0x804D1F2: evpoll (evpoll.c:92)
==3618==    by 0x4205053: ??? (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3618==    by 0x4205478: g_main_loop_run (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3618==    by 0x8049AA6: main (main.c:171)
==3618==  Address 0x47f3258 is 64 bytes inside a block of size 76 free'd
==3618==    at 0x402A3A8: free (vg_replace_malloc.c:473)
==3618==    by 0x42E7FD1: ??? (in /usr/lib/i386-linux-gnu/libtalloc.so.2.1.5)
==3618==    by 0x804A3FD: call_leg_release (call.c:87)
==3618==    by 0x804A186: app_mncc_disconnected (app.c:48)
==3618==    by 0x804B52D: close_connection (mncc.c:255)
==3618==    by 0x804BCFA: mncc_rtp_send.constprop.13 (mncc.c:145)
==3618==    by 0x804CC86: check_setup (mncc.c:435)
==3618==    by 0x804CC86: mncc_data (mncc.c:795)
==3618==    by 0x42FCF94: osmo_fd_disp_fds (select.c:167)
==3618==    by 0x804D1F2: evpoll (evpoll.c:92)
==3618==    by 0x4205053: ??? (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3618==    by 0x4205478: g_main_loop_run (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3618==    by 0x8049AA6: main (main.c:171)
==3618==

Change-Id: I1889013ed315f896e4295358f6daf76ce523dc2a
2017-03-06 21:10:07 +00:00
Holger Hans Peter Freyther 068f547954 call: Fix call release handling on mncc connection loss
The app_mncc_disconnected will be called when the MNCC socket is down
and lead to all calls being released. It directly released the call but
did not stop the MNCC CMD timer. Go through the call release callback.

==3618==    at 0x804A18A: app_mncc_disconnected (app.c:49)
==3618==    by 0x804B52D: close_connection (mncc.c:255)

This lead to the timer not being removed:

==3593== Invalid read of size 4
==3593==    at 0x4305D42: rb_first (rbtree.c:294)
==3593==    by 0x42FCB37: osmo_timers_update (timer.c:220)
==3593==    by 0x804D1D5: evpoll (evpoll.c:89)
==3593==    by 0x4205053: ??? (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3593==    by 0x4205478: g_main_loop_run (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3593==    by 0x8049AA6: main (main.c:171)
==3593==  Address 0x47f3380 is 232 bytes inside a block of size 272 free'd
==3593==    at 0x402A3A8: free (vg_replace_malloc.c:473)
==3593==    by 0x42E7FD1: ??? (in /usr/lib/i386-linux-gnu/libtalloc.so.2.1.5)
==3593==    by 0x804A3C4: call_leg_release (call.c:83)
==3593==    by 0x804A188: app_mncc_disconnected (app.c:48)
==3593==    by 0x804B52D: close_connection (mncc.c:255)
==3593==    by 0x804BCFA: mncc_rtp_send.constprop.13 (mncc.c:145)
==3593==    by 0x804CC86: check_setup (mncc.c:435)
==3593==    by 0x804CC86: mncc_data (mncc.c:795)
==3593==    by 0x42FCF94: osmo_fd_disp_fds (select.c:167)
==3593==    by 0x804D1F2: evpoll (evpoll.c:92)
==3593==    by 0x4205053: ??? (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3593==    by 0x4205478: g_main_loop_run (in /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1)
==3593==    by 0x8049AA6: main (main.c:171)

Change-Id: I2e8e14b3983f84c9be046bbd96bbcd1e5766993e
2017-03-06 21:10:07 +00:00
Holger Hans Peter Freyther 42b073a233 evpoll: Don't try to be more smart than g_poll
gpoll.c:g_poll maps G_IO_PRI (which is POLLPRI) to the errorfds of
the select call. Let's do the same.

Change-Id: I8c9163f7495e0b237bde2d48beffea3b0776a1dd
Related: OS#1934
2017-02-11 13:06:32 +07:00
Holger Hans Peter Freyther e19f9ce39f evpoll: Always initialize revents for the output
Even if we have not selected the fd (e.g. fd < 0), initialize revents
to 0. This seems to match gpoll.c:g_poll of glib.

Change-Id: I9e16a6d5a74a204c85808ba67a8f0f7af3045059
2017-02-11 13:01:12 +07:00
Holger Hans Peter Freyther 70926c8bb5 evpoll: Use {} in the middle of the if/else if/else block
Curly braces are used the lines above and below, don't make the middle
stick out like this.

Change-Id: I48a15a8665a47db206f8a7ccbc792f6bec8549c2
2017-02-11 13:00:19 +07:00
Holger Hans Peter Freyther 14488c1c46 sip: Treat SIP 183 as progress too
It doesn't fix early media yet but brings us one step
closer to it:

   The 183 (Session Progress) response is used to convey information
   about the progress of the call that is not otherwise classified.  The
   Reason-Phrase, header fields, or message body MAY be used to convey
   more details about the call progress.

Change-Id: Ibf264f251e41c06a7b4839acc0d0853e6400291c
2017-02-11 04:53:16 +01:00
Neels Hofmeyr c403ed69cd log VTY telnet bind only once
After libosmocore 55dc2edc89c1a85187ef8aafc09f7d922383231f which outputs
'telnet at <ip> <port>' from telnet_init_dynif(), there's no need to log the
telnet VTY bind here anymore.

Change-Id: I7db7f7a2e61ba676c2712bcc149a5fd5a69b80b2
2016-09-26 22:56:27 +02:00
Holger Hans Peter Freyther 550264987f sip: Start the application even if sofia-sip is broken
In case of solely managing the application through the VTY we
want/need to have the application running besides a wrong config
has been entered. SIP will be broken but a user will be able to
see the log message and can fix it.
2016-05-07 11:52:24 +02:00
Holger Hans Peter Freyther e932949ac0 distcheck: Package the logging.h file as well 2016-04-24 22:30:26 +02:00
Holger Hans Peter Freyther d1c11b1e97 vty: Add VTY command about the state of the mncc connection
Add VTY command with the state of the MNCC connection. It gives
a simple state and is connected in case of the READY state.
2016-04-04 20:17:29 +02:00
Holger Hans Peter Freyther 02b19354e4 mncc: Use strcpy for these routines and not memcpy
We need to stop on the first occurence of a \0 in the address
provided by SIP. Do not copy the full amount of bytes.
2016-04-04 20:16:27 +02:00
Holger Hans Peter Freyther 79538fc220 vty: Add extended show calls command with all information
Print everything we know about the call. This can be useful to debug
stuck calls or similiar events.
2016-04-04 20:09:02 +02:00
Holger Hans Peter Freyther 211ad859de sip/call/mncc: Move source/dest into the call structure
In preparation of a better show calls VTY command it is of interest
to know which number has been dialed by whom. For that store the
source/dest in there.

MNCC: Change the talloc root context to the call and don't try to
free the strings after calling the routing code

SIP: Use talloc_strdup to duplicate them.

Call: Add null check because the talloc_strdup of the SIP layer
could have failed.
2016-04-04 19:52:41 +02:00
Holger Hans Peter Freyther 32162fe7c8 vty: Fix the number of documented arguments 2016-04-04 18:31:34 +02:00
Holger Hans Peter Freyther c39c3df251 vty: Add simple VTY output for current calls
Start with a show call summary that lists simple data about the
current set of calls:

Call(5002) initial(type=SIP,state=CONFIRMED) remote(type=MNCC,state=INITIAL)
Call(5001) initial(type=MNCC,state=PROCEEDING) remote(type=SIP,state=CONFIRMED)

Related: OS#1680
2016-04-04 17:09:30 +02:00
Holger Hans Peter Freyther b2b13f69ae mncc: Use snprintf correctly create format specifier
I was focusing so much on the length that I didn't notice the
wrong usage of snprintf. Correct it.

Warning on Ubuntu:
mncc.c:679:3: warning: format not a string literal and no format arguments [-Wformat-security]
   snprintf(mncc.imsi, 15, called);
2016-04-04 16:26:50 +02:00
Holger Hans Peter Freyther 270c73c11f mncc: Reject hold requests for now
MNCC hold to sip has not been implemented, so let me reject the
request right now. A ticket (OS#1686) has been filed to track
implementing call holding.
2016-04-04 12:38:10 +02:00
Holger Hans Peter Freyther 6d7d7f2cd3 mncc: Have all release go through a local method
Have all release go through a local method first. This way we can
make sure to stop the timer. I have seen something odd (a busy loop
in the RB tree of the timer code) and we can easily avoid having a
timer run on a page of memory that has been "freed".
2016-04-04 12:38:01 +02:00
Holger Hans Peter Freyther c313ab0f6b mncc: Only copy 15 chars to leave the last one as NULL
Right now we are lucky the next byte after imsi is already set
to NUL here but we should not rely on that.
2016-04-01 15:42:41 +02:00
Holger Hans Peter Freyther 3d2787646b app/mncc: Add "use-imsi" to allow calling by IMSI
In case one is using a PBX it might be the easiest just to
call based on IMSI. Add a VTY option to enable/disable this
feature. It can be used to keep the number assignment outside
of the HLR database.
2016-04-01 15:35:29 +02:00
Holger Hans Peter Freyther bec32eb207 coverity: Address two issues found by coverity
Add NULL check in the case of MNCC disconnect that was missing and
add an assert to show that at this point the other leg must exist.

Fixes: CID#80799, CID#80800, 80801
2016-03-31 19:36:27 +02:00
Holger Hans Peter Freyther 2a7cfb5c93 sip/sdp: Hack to get a GSM codec call connected
Extract IP and port once we have received the INVITE. In the near
future we need to improve this!
2016-03-31 16:28:21 +02:00
Holger Hans Peter Freyther c2474dc0be mncc: Add handling to connect a MNCC MT call
This will go through the stage of:

* MNCC_CALL_CONF_IND (to which we create a RTP socket)
* then we might receive a MNCC_ALERT_IND
* and finally the MNCC_SETUP_CNF

For the last two we inform the other leg about the progress.
2016-03-31 16:06:04 +02:00
Holger Hans Peter Freyther 8763cf8850 sip: Pass to not enable media on our 200 response
In case we send a 200 but don't have this tag, a 500 response will
be sent and the call will be dropped.
2016-03-31 16:04:47 +02:00
Holger Hans Peter Freyther 275571ff20 mncc: Introduce direction and start to handle it separetely
For releasing a MT-Call we will need to send a release request
and then wait for the release confirmation. Add if/else to it.
If this turns out to be too ugly we will be able to create one
MO and one MT leg.
2016-03-31 14:17:58 +02:00
Holger Hans Peter Freyther 4bfaf60ed2 mncc: Convert ip address so BTS sends it to the right place 2016-03-31 14:17:33 +02:00
Holger Hans Peter Freyther b8e802851d mncc: Handle REJ_IND from the NITB
In case a call can not be connected we will receive a REJ.IND.
Inform the other leg and release the call.
2016-03-27 17:05:48 +02:00
Holger Hans Peter Freyther a4970327f2 mncc: Stop timer when starting the release process 2016-03-27 17:05:48 +02:00
Holger Hans Peter Freyther 00a43e20ab mncc: On timeout release the other leg as well
In case we don't receive the response we had expected let us
take down the other part of the call as well.
2016-03-27 17:05:48 +02:00
Holger Hans Peter Freyther 916348b7dc mncc: Begin to implement MT call handling for SIP->MNCC
Initiate the setup request that should result in the call getting
all the way to the connected state at some point in time. The device
I test with sadly rejects the call too soon.
2016-03-27 17:02:39 +02:00
Holger Hans Peter Freyther 80880d45b7 sip: Refactor sdp file creation and implement alert+connect
The codec negotiation is still a huge todo and the initial version
will be far from perfect. We will use whatever MNCC has decided on
and then see if it is compatible in the end.
2016-03-26 22:11:06 +01:00
Holger Hans Peter Freyther dac13bed50 sip/app: Route call from SIP to MNCC and deal with the release
Fix releasing of the leg in case it is not routable and make the
differentation if we initiated the invite (send CANCEL) or send
a final error. The error code was randomly picked and once we have
an enum of causes we can decide where to map it to.
2016-03-26 21:09:07 +01:00
Holger Hans Peter Freyther 7a30c94030 sip: Continue SIP->MNCC (MO or SIP Originated) implementation
Copy out to/from numbers, copy the sdp file, set the magic for the
nh handle. With the incoming cancel the leg and the entire call will
be terminated.
2016-03-26 20:55:02 +01:00
Holger Hans Peter Freyther 5f29be5acf sip: Actually return after having rejected the new call 2016-03-26 20:30:14 +01:00
Holger Hans Peter Freyther 392313ff73 sdp: Extract SDP traversing into a separate module
The code will still know about SIP and the sip_call_leg but is
now separate of the call handling logic.
2016-03-26 20:02:06 +01:00
Holger Hans Peter Freyther b723cceee9 call: Create a call with a SIP leg
Clone the MNCC code and create a call with a SIP leg.
2016-03-26 19:51:33 +01:00
Holger Hans Peter Freyther 586abf9f0f sip: Handle incoming message and screen the SDP file
Check if the SDP file has any codec potentially supported by GSM.
The topic of codec selection is a complicated one and we will not
support it correctly in the beginning.
2016-03-26 19:44:03 +01:00
Holger Hans Peter Freyther 6f039c158d sip: Mark call as MT call in preparation for incoming calls 2016-03-26 19:03:04 +01:00
Holger Hans Peter Freyther b927a0bbde call: It is call_create and not sip_create
It is not creating anything related to sip at all. Remove the
prefix in preparation to creating a call from a sip_call_leg.
2016-03-26 18:52:22 +01:00
Holger Hans Peter Freyther 989bef0875 app: Translate payload name to IETF codec name
Convert the MNCC codec type to the IETF codec name.
2016-03-26 16:33:15 +01:00
Holger Hans Peter Freyther 997d72e0fe app: Ask the sip side to create a leg
Create SIP leg and if it is failing release the call
2016-03-26 06:22:07 +01:00
Holger Hans Peter Freyther 2211c3ba56 sip: Implement MT call out to SIP
* Create a new handle
* Send the invite
* Have some state transitions
* Allow to release a call in initial unconfirmed state, confirmed
one with cancel and connected with bye
* Add simple SDP parsing to find the rtpmap/codec that is used by
gsm
2016-03-26 06:22:06 +01:00