aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmgcp/mgcp_protocol.c
AgeCommit message (Collapse)AuthorFilesLines
2014-09-04mgcp: Store one more codec/payload type if it is presentHolger Hans Peter Freyther1-7/+18
In case of some RTP proxy from time to time we are offered both G729 and G711 but only one of them will work. I intend to adjust the codec at runtime in case we receive the wrong codec.
2014-09-04mgcp: Group codec reset and put it to a separate method.Holger Hans Peter Freyther1-9/+15
2014-09-04mgcp: Move the "codec" params to a structHolger Hans Peter Freyther1-39/+39
We might be offered multiple codecs by the remote and need to switch between them once we receive data. Do this by moving it to a struct so we can separate between proposed and current codec. In SDP we can have multiple codecs but a global ptime. The current code doesn't separate that clearly instead we write it to the main codec. Conflicts: openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c
2014-07-22mgcp: Change API to remove memory management from the nameHolger Hans Peter Freyther1-6/+11
Jacob pointed out that "free_endp" refers to the memory of the endpoint being freed. What we want is actually a way to release an endpoint (and the resource it allocated) or in the case of the testcase/testapp initialize the data structure correctly. Introduce two names for that.
2014-07-08osmux: Make sure to always use the right dummy sending methodHolger Hans Peter Freyther1-6/+11
Make sure to re-use the right method for nat traversal. Found by Roch while looking at traces.
2014-06-15mgcp: Fix SDP formatting of fmtp_extra (Coverity)Jacob Erlbeck1-2/+1
Currently when ftmp_extra is set, a doubled a=rtpmap line is emitted instead of the fmtp_extra info. This patch fixes replaces the formerly copied and pasted but not modified snprintf parameters by the correct ones. Fixes: Coverity CID 1220873 Sponsored-by: On-Waves ehf
2014-06-05mgcp: Set net_end audio params in recvonly modeJacob Erlbeck1-3/+38
Currently, if there is no SDP data in the MGCP message received from the net, the fields containing audio encoding information are not set in net_end. So in recvonly mode transcoding would not be set up correctly. This patch changes the implementation of the code handling CRCX and MDCX to use the codec signalled in the MGCP local connection options (field 'a:') if there isn't any SDP data. This is only halfway negotiation, because the codec is used blindly and not matched against the supported ones. Sponsored-by: On-Waves ehf
2014-06-05mgcp: Add packet size (ptime) conversionJacob Erlbeck1-2/+16
The current transcoder implemenation always does a 1:1 recoding concerning the duration of a packet. So RTP timestamps and sequence numbers are not modified. This is not sufficient in some cases, e.g. when the BTS does only allow for a single fixed ptime. This patch decouples encoding from decoding and moves the decoded samples to the state structure so that samples can be combined or drain according to the packaging of incoming and outgoing packets. This patch incorporates parts of Holger's experimental fixes in 0e669e05^..9eba68f9. Ticket: OW#1111 Sponsored-by: On-Waves ehf
2014-06-05mgcp: Only include SDP lines with valid contentJacob Erlbeck1-43/+90
Don't show media related lines if the payload type has not been set. Don't show a 'a=rtpmap' line if the audio_name has not been set. This patch unifies the SDP generation of create_response_with_sdp() and send_msg(). Sponsored-by: On-Waves ehf
2014-06-05mgcp: Add a function to get media info for MGCP responsesJacob Erlbeck1-5/+14
This patch adds the get_net_downlink_format_cb() callback to provide payload_type, subtype_name, and fmtp_extra suitable for use in a MGCP response sent to the network. Per default, the BTS side values are returned since these must be honoured by the net peer when sending audio to the media gateway (unless transcoding is done). Sponsored-by: On-Waves ehf
2014-06-05mgcp: Add audio info fields to struct mgcp_rtp_endJacob Erlbeck1-20/+64
This patch adds the fields channels, subtype_name, and audio_name to the struct. The field audio_name contains the full string that has been used for the last part of a SDP a=rtpmap line. The others contain decoded parts of that string. If no a=rtpmap line has been given (e.g. because dynamic payload types are not used), values are assigned when the payload type matches one of the predefined ones (GSM, G729, PCMA). The patch also moves the audio_name parsing code to a dedicated set_audio_info() function. Sponsored-by: On-Waves ehf
2014-06-05mgcp: Add callbacks for payload processingJacob Erlbeck1-1/+33
This patch adds the callbacks rtp_processing_cb and setup_rtp_processing_cb to mgcp_config to support arbitrary RTP payload processing. Sponsored-by: On-Waves ehf
2014-05-28mgcp: Address scanf issue already found by cppcheck and now ASANHolger Hans Peter Freyther1-1/+1
Use the right size for scanf. ================================================================= ==6106== ERROR: AddressSanitizer: unknown-crash on address 0xbffff4b0 at pc 0xb69d87fd bp 0xbffff248 sp 0xbffff21c WRITE of size 65 at 0xbffff4b0 thread T0 #0 0xb69d87fc (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0xa7fc) #1 0xb69d9239 (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0xb239) #2 0xb69d92d6 (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0xb2d6) #3 0x804f151 (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x804f151) #4 0x80531e8 (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x80531e8) #5 0x8051e6f (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x8051e6f) #6 0x8049b0a (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x8049b0a) #7 0x804bd9e (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x804bd9e) #8 0xb6778a62 (/lib/i386-linux-gnu/i686/cmov/libc-2.18.so+0x19a62) #9 0x8049330 (/home/ich/source/gsm/openbsc/openbsc/tests/mgcp/mgcp_test+0x8049330) Address 0xbffff4b0 is located at offset 416 in frame <parse_sdp_data> of T0's stack: This frame has 8 object(s): [32, 36) 'audio_payload' [96, 100) 'payload' [160, 164) 'channels' [224, 228) 'ptime' [288, 292) 'port' [352, 368) 'ipv4' [416, 480) 'audio_name' [512, 576) 'audio_codec' HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext (longjmp and C++ exceptions *are*
2014-05-22mgcp: Add proper length checking for line handlingHolger Hans Peter Freyther1-0/+22
In ae1997248ccb4fba1394267d3051082dfd85448a the handwritten tokenizer was replaced with strtok_r. As part of this change the structural checking of MGCP parameters was stopped. This means that a code like "line + 3" might access beyond the first NUL and be possibly behind the msgb. Manually add size checking again. Manually jumping to the error label is not possible anymore as it has been removed. The result is that invalid lines will be skipped. This is matching the general approach by the IETF RFCs to be permissive in data being received.
2014-05-22mgcp: add voice muxer supportPablo Neira Ayuso1-5/+37
This patch adds the voice muxer. You can use this to batch RTP traffic to reduce bandwidth comsuption. Basically, osmux transforms RTP flows to a compact batch format, that is later on decompacted to its original form. Port UDP/1984 is used for the muxer traffic between osmo-bsc_nat and osmo-bsc_mgcp (in the BSC side). This feature depends on libosmo-netif, which contains the osmux core support. Osmux is requested on-demand via the MGCP CRCX/MDCX messages (using the vendor-specific extension X-Osmux: on) coming from the BSC-NAT, so you can selectively enable osmux per BSC from one the bsc-nat.cfg file, so we have a centralized point to enable/disable osmux. First thing you need to do is to accept requests to use Osmux, this can be done from VTY interface of osmo-bsc_nat and osmo-bsc_mgcp by adding the following line: mgcp ... osmux on osmux batch-factor 4 This just initializes the osmux engine. You still have to specify what BSC uses osmux from osmo-bsc_nat configuration file: ... bsc 1 osmux on bsc 2 ... bsc 3 osmux on In this case, bsc 1 and 3 should use osmux if possible, bsc 2 does not have osmux enabled. Thus, you can selectively enable osmux depending on the BSC, and we have a centralized point for configuration from the bsc-nat to enable osmux on demand, as suggested by Holger. At this moment, this patch contains heavy debug logging for each RTP packet that can be removed later to save cycles. The RTP ssrc/seqnum/timestamp is randomly allocated for each MDCX that is received to configure an endpoint.
2014-01-20mgcp: Synchronize conn mode bits and output enabled flagsJacob Erlbeck1-24/+7
This patch changes implementation and the mgcp_connection_mode enum in a way that net_end.output_enabled (bts_end.output_enabled) flag always matches the MGCP_CONN_SEND_ONLY (MGCP_CONN_RECV_ONLY) bit of conn_mode. Based on this, the conn_mode bits are then used instead of the output_enabled fields within mgcp_protocol.c. Sponsored-by: On-Waves ehf
2014-01-20mgcp: Disable output enabled on initialisationJacob Erlbeck1-1/+1
Currently RTP output_enabled is set to 1 on initialisation, which does not semantically match the initial value of conn_mode (MGCP_CONN_NONE). This patch changes this initial value to 0. Sponsored-by: On-Waves ehf
2014-01-16mgcp: Send RTP keepalive dummy packets to netJacob Erlbeck1-0/+43
So far, a single dummy packet has been sent immediately after the reception of a MDCX message. There is no dedicated keep alive mechanism (it just worked because the audio from the MS has always been forwarded to the NAT until the 'mgcp: Set output_enabled flags based on the MGCP mode' patch). This patch adds explicit, timer based keep alive handling that can be enable per trunk. A VTY command 'rtp keep-alive' command is added for configuration which can be used to set the interval in seconds, to send a single packet after the reception of a CRCX/MDCX when RTP data from the net is expected ('once'), or to disable the feature completely ('no rtp keep-alive'). In 'send-recv' connections, only the initial packet is sent if enabled (even when an interval has been configured). The default is 'once'. Note that this removes the mgcp_change_cb() from mgcp_main.c. Sponsored-by: On-Waves ehf
2014-01-16mgcp: Set output_enabled flags based on the MGCP modeJacob Erlbeck1-7/+30
This patch enhances parse_conn_mode() to set the output_enabled flags of each end based on the MGCP mode. Ticket: OW#1044 Sponsored-by: On-Waves ehf
2014-01-16mgcp/rtp: Add flag to disable RTP outputJacob Erlbeck1-0/+2
This patch make it possible to have a valid endpoint that drops all outgoing RTP packets. The number of dropped packets is shown by the VTY 'show mgcp' command. By default, this feature is disabled. To enable packet dropping, the corresponding output_enabled field must be set to 0. Ticket: OW#1044 Sponsored-by: On-Waves ehf
2013-12-19mgcp/rtp: Only patch timestamp alignment errorsJacob Erlbeck1-2/+2
Currently, all timestamps are force to SeqNo*d + C which is more than required by the nanoBTS which seems to be sensitive to alignment errors only (dTS != k*d, d = ptime * rate = 160). This patch replaces the force_constant_timing feature by a force_aligned_timing feature. The timestamp offset will only be changed (and timestamp errors counted) when the alignment does not match to the raster based on ptime (default 20ms). The VTY interface does not change. Sponsored-by: On-Waves ehf
2013-12-13mgcp: Optionally send ptime in SDPJacob Erlbeck1-1/+22
Currently the SDP 'ptime' media attribute is never set in generated MGCP responses. This patch optionally includes the 'ptime' attribute if packet_duration_ms is != 0. This behaviour can be enabled/disabled by using the VTY command "sdp audio-payload send-ptime" (enabled by default). Sponsored-by: On-Waves ehf
2013-12-13mgcp: Parse SDP to get rate and packet durationJacob Erlbeck1-6/+47
This patch parses the 'ptime' and 'maxptime' SDP attributes, and the SDP rate information and sets up packet_duration_ms accordingly. If the packet duration is unknown or allows for different values (e.g. because 'ptime' uses a range or 'maxptime' allows for more than one frame) the duration is set to 0. Sponsored-by: On-Waves ehf
2013-12-13mgcp: Put local connection options into a structJacob Erlbeck1-5/+28
Currently the local connection options have been stored as a string. This patch replaces this string by a struct (that still contains a string) along with the parsed fields (only the packetization period at the moment). It also re-adds the calls to set_local_cx_options() to the handle_create_con() and handle_modify_con() functions. Except for the test program this has no side effects, since the LCO values aren't used yet.
2013-12-10mgcp/rtp: Refactored packet_duration computationJacob Erlbeck1-3/+21
Since the packet duration is given in ms with the 'ptime' RTP media attribute and also with the 'p' MGCP local connection option, the computation is changed to use this value (if present). The computation assumes, that there are N complete frames in a packet and takes into account, that the ptime value possibly had been rounded towards the next ms value (which is never the case with a frame length of exact 20ms). Sponsored-by: On-Waves ehf
2013-12-10mgcp/rtp: Only patch SSRC once after MDCX if enabledJacob Erlbeck1-1/+3
Currently the output SSRC is always forced to be the same if SSRC patching is enabled. This patch modifies this to optionally restrict the number of SSRC changes that will be corrected. Note that the configuration only allows for the 'once' mode and 'off'. Sponsored-by: On-Waves ehf
2013-12-10mgcp/rtp: Add RTP header patch mode configurationJacob Erlbeck1-1/+20
This adds datastructures and a VTY frontend to configure the different type of RTP header patching: SSRC and timestamp. Note that timestamp patching is not yet implemented. Sponsored-by: On-Waves ehf
2013-12-05mgcp: Handle SDP in CRCX received by the MGWJacob Erlbeck1-0/+9
So far the SDP part of the CRCX message has been ignored by the MGW. This patch adds SDP parsing for this case, eventually updating the net end's payload type and connection parameters. Sponsored-by: On-Waves ehf
2013-12-05mgcp: NUL-terminate MGCP messageJacob Erlbeck1-1/+15
The MGCP message isn't always NUL-terminated when arriving at mgcp_handle_message(). This may lead to undefined results. This patch ensures that the message text is NUL-terminated by setting *msg->tail to '\0' in mgcp_handle_message(). Addresses: <000b> mgcp_protocol.c:642 Unhandled option: 'r'/114 on 0x3 <000b> mgcp_protocol.c:593 Unhandled SDP option: '='/61 on 0x3 <000b> mgcp_protocol.c:871 Unhandled option: '.'/46 on 0x2 Sponsored-by: On-Waves ehf
2013-12-05mgcp: Refactor MGCP/SDP parsingJacob Erlbeck1-32/+66
This patch separates the SDP parsing from the (message specific) MGCP parsing. Sponsored-by: On-Waves ehf
2013-12-05mgcp: Add new for_each_line macro that also returns empty linesJacob Erlbeck1-0/+32
This patch add the for_each_line macro based on a strline_r() function (similar to strtok_r()), that is also part of this patch. This strline_r() function is tolerant with respect to line endings, it supports CR-only, CRLF, and LF-only and any combinations thereof (note that a CRLF is always detected as a single line break). Similar to for_each_non_empty_line (the former for_each_line) where the 'save' pointer needed to be initialised by a call to strtok_r(), the new for_each_line macro expects, that the 'save' pointer has been initialised by a call to strline_r(). Also note, that for_each_line/strline_r and for_each_non_empty_line/strtok_r may use the 'save' pointer differently, so calls to them can not be mixed. Sponsored-by: On-Waves ehf
2013-12-05mgcp: Rename for_each_line to for_each_non_empty_lineJacob Erlbeck1-6/+6
The implementation of for_each_line is based on strtok() and skips any sequence of CR and LF. Thus empty lines are never detected. There exists code which tests for an empty line to detect the beginning of the SDP part which is dead code currently (the parser works nevertheless due to other reasons). So the semantics of this macro have been misunderstood at least once. This patch renames the macro to reflect the semantics more precisely. Sponsored-by: On-Waves ehf
2013-11-25mgcp/rtp: Fix timestamp offset when patching RTP packetsJacob Erlbeck1-0/+12
The current implementation increments the seqno but does not increment the RTP timestamp, leading to two identical timestamps following one after the other. This patch fixes this by adding the computed tsdelta when the offset is calulated. In the unlikely case, that a tsdelta hasn't been computed yet when the SSRC changes, a tsdelta is computed based on the RTP rate and a RTP packet duration of 20ms (one speech frame per channel and packet). If the RTP rate is not known, a rate of 8000 is assumed. Note that this approach presumes, that the per RTP packet duration (in samples) is the same for the last two packets of the stream being replaced (the first one). Sponsored-by: On-Waves ehf
2013-11-25mgcp/rtp: Add counter for invalid RTP timestamp deltasJacob Erlbeck1-4/+20
This patch modifies the patch_and_count() function to check for RTP timestamp inconsistencies. It basically checks, whether dTS/dSeqNo remains constant. If this fails, the corresponding counter is incremented. There are four counter for this: Incoming and outgoing, each for streams from the BTS and the net. Note that this approach presumes, that the per RTP packet duration (in samples) remains the same throughout the entire stream. Changing the number of speech frames per channel and packet will be detected as error. In addition, the VTY command 'show mgcp' is extended by an optional 'stats' to show the counter values, too. Ticket: OW#964 Sponsored-by: On-Waves ehf
2013-07-08libmgcp: add enum mgcp_type and use itPablo Neira Ayuso1-4/+4
This patch replaces the field 'is_transcoded' in the mgcp_endpoint structure by the enum mgcp_type, that can be further extended with new types.
2013-07-03mgcp: Make sure the save pointer is initialized with NULL.Holger Hans Peter Freyther1-1/+1
Coverity is not happy about it but it doesn't appear to be a real issue as the data will not be NULL on the first call. Addresses: Coverity CID 1040704
2013-05-21mgcp: Initialize the tone to CHAR_MAX as this might not be a requestHolger Hans Peter Freyther1-1/+1
The RQNT message might not contain a 'S:' line with the actual tone to play. Instead of calling the callback with the 0 as tone just leave early. Example: X: 6B9519B88F0 R: D/[0-9#*](N), G/ft, fxr/t38
2013-04-16nat: We want the remote to respond to our DLCX requestHolger Hans Peter Freyther1-1/+29
We want to send a TRAP with the MGCP statistics from the NAT and the connected BSC. The BSC endpoint can be either released because of a DLCX from the MGCP CallAgent or the SCCP Connection release on the A-link. This is why we need to queue the statistics when the deleting the endpoint on the BSC. The processing is continued once the response arrives. This code assumes that the response of the DLCX will be sent by the remote side. The current amount of outstanding responses can be seen on the VTY. This assumption is based on the fact that the BSC has already responded to the CRCX and maybe to the MDCX. The MGCP RFC is bended to prefix the transaction identifier with "nat-" to easily detect the response and hand it to the handler. This will then parse the response and generate the TRAP. The current version is v1. We assume that the transaction space is big enough and we will not re-assign the transaction identifier too early.
2012-12-16mgcp: Allow to freely control the a=fmtp line for experimentsHolger Hans Peter Freyther1-2/+9
In case of AMR one can specify the available codecs out-of-band. Allow to configure this line statically in the configuration file.
2012-12-10mgcp: Test and implement re-transmission handlingHolger Hans Peter Freyther1-161/+161
MGCP is used over UDP and a response might be lost. The MGCP RFC asks for keeping a list of responses and then using the previous response to answer a duplicate request. I tried to conserve memory and just wanted to remember the last transaction identifier and result-code and re-generate the result from that. This made the code look bad and this is why the entire response will now be stored. It sadly increases the memory usage but can not be avoided at this time. Remove the msg->l3h pointer for the RQNT callback as strtok has modified the content of it.
2012-12-10mgcp: Change the flow of the code when handling a MGCP responseHolger Hans Peter Freyther1-11/+14
Attempt to detect a response and return only then. Remove one level of tabls in preparation for the re-transmission handling.
2012-12-10mgcp: Methods generating a response now include the endpoint pointerHolger Hans Peter Freyther1-37/+35
This is required for remembering the last result in a central place and is required to properly implement detection of re-transmissions.
2012-12-10mgcp: Fix a typo.. it is msg and not mgsHolger Hans Peter Freyther1-1/+1
2012-12-10mgcp: We do not need to check for talloc_freeHolger Hans Peter Freyther1-8/+4
Simplify the code and remove null check for the two strings.
2012-11-29mgcp: Begin handling of the RQNT message as needed for DTMFHolger Hans Peter Freyther1-11/+47
Introduce a callback for the request and forward the signalrequest to the callback. This is not a full implementation of MGCP RQNT.
2012-11-12mgcp: Send the jitter statistics at the end of the callHolger Hans Peter Freyther1-3/+4
2012-11-12mgcp: Calculate the packet loss as of Appendix A of RFC 3550Holger Hans Peter Freyther1-2/+8
Calculate the expected packages and packet loss as of RFC 3550. The values should be clamped but our packet loss counter is 32 bits and not 24 and we should clamp at other values but I am waiting for some issues first before dealing with that.
2012-11-12mgcp: Include statistics at the end of a connectionHolger Hans Peter Freyther1-9/+36
Follow the MGCP specification and send the collected statistics at the end of a call. Right now this does not include jitter, packet loss and delay.
2012-11-12mgcp: Count the received octets as of the MGCP specificationHolger Hans Peter Freyther1-0/+1
Count the received octets. This is encouraged by the MGCP specification. Use a 32bit counter that is good enough for more than 12 hours of a EFR call. This limit is good enough for the current configuration.
2012-05-11mgcp: Make it possible to drop RTCP packets coming from the BTS/NetHolger Hans Peter Freyther1-0/+2
The ip.access nanoBTS appears to send quite broken NTP timestamps in the RTCP messages might confuse equipment that uses the sender report of the BTS. Make it easy to experiment by adding an option to drop RTCP.