Commit Graph

45 Commits

Author SHA1 Message Date
Max b27e6feb69 Rename msgb_wrap_with_TL()
This resolves an issue introduced in 84fb5bb6a0
when msgb_wrap_with_TL() was introduced as an inline function with
*exactly the same name* as in osmo-msc.git and openbsc.git.  We *NEVER*
do something like this.  Functions moved from applications to library
*MUST* always be renamed.  This has been the case for almost a decade
now.

With this subsequent change we make sure the libosmocore function
has a different name and doesn't clash.  After this commit, old
openbsc.git and osmo-bsc.git should again build fine.

Change-Id: If1e851ac605c8d2fde3da565b0bd674ea6350c2e
2019-01-21 13:47:08 +00:00
Max e035572ea8 Fix typos in SS opcode names
Change-Id: I8fa1961c85b3fd714bc8df56fe4af6be4060c208
2018-12-19 13:52:28 +01:00
Vadim Yanitskiy d8fcef7794 gsm0480: fix copy-pasted note for gsm0480_gen_return_error()
InvokeID is mandatory for ReturnError component.

Change-Id: Ie1c7116d368c2029b9f524cb74ffa316e282ec83
2018-12-14 00:31:06 +00:00
Max 84fb5bb6a0 Move msgb_push helpers to public header
The msgb_wrap_with_TL() is generally useful so it make sense to make it
public to facilitate code re-use.

Other helpers can be implemented as trivial wrappers over existing tlv.h
functions. Update headers and code accordingly.

Change-Id: I37e91d031fba28cf1c6735b8069b0265746f55e6
2018-11-19 05:47:25 +00:00
Vadim Yanitskiy 30cfeeb4a0 libosmogsm: (re)introduce gsm48_push_l3hdr()
There was gsm0480_l3hdr_push() declared in a header file, but
not exposed in 'libosmogsm.map'. Furthermore, for some reason
it was a part of GSM 04.80 API, what is not actually correct.

Let's rename this symbol, and properly expose it as a part of
the GSM 04.08 API. Also, let's introduce an auxiliary wrapper
for messages, where the transaction identifier is required
(see GSM 04.07, section 11.2.3.1.2).

Change-Id: I8a045efe8335d83fcbe8d43eb180972e3b1d9dda
2018-08-05 23:21:43 +07:00
Vadim Yanitskiy 39a36d0193 gsm/gsm0480.c: use the local msgb allocator
Change-Id: I23b4b0e1c237b9b27c1db1c9a824b5329d41a38b
2018-08-05 14:48:27 +07:00
Vadim Yanitskiy 3fc4616224 gsm/gsm0480.c: prevent NULL-pointer dereference
Change-Id: I444d95941837458b46e581298f76f3a9926c8552
2018-08-05 07:14:19 +00:00
Harald Welte 7ecc4a3171 04.80: New gsm0480_gen_{reject,return_error}() functions
Add functions to generate TS 04.80 (supplementary services)
Reject and ReturnError components.

Change-Id: I6e5ee39c3d03364f7833ec717593d5ddb0a4c5f9
2018-07-29 14:39:36 +00:00
Harald Welte b0d9594081 USSD: Introduce gsm0480_gen_ussd_resp_7bit()
Contrary to the existing gsm0480_create_ussd_resp(), the new function
only generates the value part of the FACILITY IE, and not the IE
Tag/Length or the 04.08 L3 header.  This is needed in the context of
GSUP-encapsulated USSD, as here we don't work with L3 messages, but
only pass on the FACILITY IE value.

Change-Id: Ide240279240322f643e142229eb7829f538c6314
2018-07-29 14:39:36 +00:00
Harald Welte 88fa5a3e1e gsm0480: Factor out msgb allocation helper function
Change-Id: If25b467481023eadaaf3f78157eceff4b81d24d2
2018-07-29 14:39:36 +00:00
Harald Welte b1a35d63b9 gsm 04.80: Add value_string for component type and op code
Change-Id: I2615a88db5224d65f37c7cc505e183ec8b196e8a
2018-06-16 18:39:59 +02:00
Vadim Yanitskiy 5a09f75c1e gsm/gsm0480: refactor and expose gsm0480_parse_facility_ie()
This function can be used when there is only a part of GSM 04.80
message available - Facility IE, e.g. when a message is carried
over GSUP/MAP. Let's expose it.

Refactoring includes the following:

  - adding the 'gsm0480_' prefix;
  - correcting inverted return value;
  - cosmetic code style changes.

Change-Id: I623c39ffbe6cdee65eade8435a2faa04d0da193e
2018-06-11 23:50:00 +07:00
Vadim Yanitskiy 52e44121db gsm/gsm0480.c: introduce gsm0480_extract_ie_by_tag()
In some cases, there is no need to parse the whole message,
e.g. during the conversion from DTAP to GSUP/MAP. This
function can be used to extract given IE from a message.

Change-Id: I3989d061903352473305f80712f1a1560d05df3d
2018-06-11 23:45:48 +07:00
Vadim Yanitskiy fb5da89579 gsm0480: fix: don't overwrite the data of RELEASE_COMPLETE
According to the 3GPP TS 04.80, table 2.5 'Release complete', a
RELEASE_COMPLETE message may containg optional FACILITY element.

Meanwhile, the 0xff byte is used to indicate that there is no
decoded message (legacy field). Let's avoid overwriting of
a decoded message.

Change-Id: I0c85292222749a48ca0c4b2e93f4fa2d61468c18
2018-05-29 19:23:42 +00:00
Vadim Yanitskiy 2ecfb30d7f gsm0480: drop messages with incorrect data length
If either an INVOKE, either a RETURN_RESULT component has the
data with incorrect length (see Annex A, 3GPP TS 04.80), the
whole message is probably incorrect.

Let's drop such messages instead of silent truncation.

Change-Id: I2a169b0b84aa26ea2521edd55ff005c27ae6d808
2018-04-04 20:24:09 +07:00
Vadim Yanitskiy a24ead0126 gsm0480: copy the raw USSD data, its DCS and length
As it was already documented before, the 'ss_request' struct has
a rudiment of deprecated 'ussd_request' struct - the 'ussd_text'
field. It represents the data either of an INVOKE component,
either of a RETURN_RESULT component, encoded as ASCII in case
if DCS is 0x0f (i.e. decoded by the code itself), otherwise
raw bytes 'as is'.

Previously, there was no possibility to distinguish between
ASCII and raw bytes with different DCS. Moreover, the payload
decoding is not desired in some cases.

Let's introduce the new fields, which will carry the raw
unmodified payload, its length and DCS (Data Coding Scheme).

Change-Id: Ia193d175021e145bb3b131290231f307dbefc64a
2018-04-04 20:22:13 +07:00
Vadim Yanitskiy 3cafc06014 gsm0480: parse optional IEs for RELEASE COMPLETE message
According to GSM 04.80 section 2.5 "Release complete", a message
of the mentioned type may contain optional IEs, such as Cause
and Facility. Let's parse them.

Change-Id: Ib8fc1f6bae472b0b264b6158f372b6cce255b222
2018-01-17 10:45:41 +00:00
Vadim Yanitskiy b92a27f694 gsm0480: parse all SS info elements in a message
Some SS messages (e.g. RELEASE COMPLETE) may contai multiple
IEs (Information Elements). Let's parse them all.

Change-Id: I20cc59c25fdbda176bcf76437174cda829518d60
2018-01-17 10:45:41 +00:00
Vadim Yanitskiy b41c70f4e6 gsm0480: correct parse_ss_info_elements() declaration
Change-Id: I64df293188908c7eb10a61941db76656340d3a8e
2018-01-17 10:45:40 +00:00
Vadim Yanitskiy f07c58cb36 gsm0480: refactor gsm0480_decode_ss_request
Change-Id: Iba734db97ab516f8fce816c4e4225b97b93619f1
2018-01-17 10:45:40 +00:00
Vadim Yanitskiy fd744ceeae gsm0480: move SS request length check to parse_ss()
Change-Id: I8e7ce5bd97f3a8731924264c92afb9a7183937dc
2018-01-17 10:45:40 +00:00
Vadim Yanitskiy 7689e0f1a2 gsm0480: pass exact GSM 04.80 payload length to parse_ss()
Change-Id: I9608d4ad16d7581320615c140beaac36628c31a4
2018-01-17 10:45:40 +00:00
Vadim Yanitskiy 44ebb939eb gsm0480: add specification reference to SS message type
Change-Id: Iff0210e995053e270939a774db33f55b22545204
2018-01-17 10:45:40 +00:00
Vadim Yanitskiy 394447bb4b gsm0480: handle GSM0480_OP_CODE_PROCESS_USS_DATA
Change-Id: I470290c2b544555e53cedd849b1d6a961db7b5a4
2018-01-17 10:45:39 +00:00
Vadim Yanitskiy 511426de0a gsm0480: handle USS_NOTIFY and USS_REQUEST with PROCESS_USS_REQ
Change-Id: If7cc6a966dfc17d37e22338ecc1f239f908a9f2e
2018-01-17 10:45:39 +00:00
Vadim Yanitskiy 7f16c443bc gsm0480: handle GSM0480_CTYPE_RETURN_RESULT
Change-Id: I8fb2856acbbf4c53e7d53200a37bc8f79e763bcf
2018-01-17 10:45:39 +00:00
Vadim Yanitskiy c30431ffc7 gsm0480: parse GSM0480_MTYPE_FACILITY separately
Change-Id: I6e029c436a50fa8c2823ea39c5d123ee701becfa
2018-01-17 10:45:39 +00:00
Vadim Yanitskiy 01b85724af gsm0480: handle UnstructuredSS Request with DSC != 0x0F
According to GSM 04.08, 4.4.2 "ASN.1 data types":
the USSD-DataCodingScheme shall indicate use of
the default alphabet using the 0x0F value.

Previously, the UnstructuredSS Request messages with not
default alphabet were not being handled. Let's fix this.

Change-Id: I73d602f6f20b0afe7600d16bbd432069ae7be788
2018-01-17 10:45:39 +00:00
Vadim Yanitskiy 5b0790df52 gsm0480: clean up the parse_process_uss_req() code
This change reduces the degree of code nesting...

Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
2018-01-17 10:45:39 +00:00
Vadim Yanitskiy fa6c2b9b53 gsm0480: fix USSD OCTET STRING length confusion
According to the GSM 04.80 (version 5.0.0) specification Annex A
"Expanded ASN.1 Module "SS-Protocol", the maximum size of a USSD
OCTET STRING is 160 bytes.

Thus according to ETSI TS 123 038 (version 10.0.0) specification
6.1.2.3 "USSD packing of 7 bit characters", in 160 octets, it's
possible to pack (160 * 8) / 7 = 182.8, that is 182 characters.
The remaining 6 bits are set to zero.

This change defines both mentioned values:

  - GSM0480_USSD_OCTET_STRING_LEN  160
  - GSM0480_USSD_7BIT_STRING_LEN   182

keeping the old MAX_LEN_USSD_STRING 'as is' due to compatibility
reasons. Now the new value is used for ss_request structure, while
old one is still used for deprecated ussd_request structure.

Change-Id: I6dead74f9ecea079752ff2400cdaf7c30187784e
2018-01-17 10:45:39 +00:00
Sergey Kostanbaev 04ee9c04f4 gsm0480: skip length check for 'RELEASE COMPLETE' message
According to GSM 04.80 Section 2.5 'Release complete' Table 2.5,
the 'RELEASE COMPLETE' message payload is optional, so let's drop
the length check in gsm0480_decode_ss_request() for this type.

Change-Id: I63b7f8ce403169a9dbdbdb031db16693de2196d6
2018-01-17 10:45:38 +00:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr bc1d758299 gsm0480: add gsm0480_create_ussd_notify() and *_release_complete()
Add two functions to create USSD messages. Moves and generalizes code from
openbsc. Pending: use the new functions in openbsc.

It looks like _release_complete() should also set trans_id and direction flag;
but since this is moving code from openbsc that is apparently working, just
place a fixme comment and don't change the functionality.

Change-Id: Ia80e32c7105359915bfad3cc5621a1c09caf20f0
2016-12-01 15:54:35 +00:00
Neels Hofmeyr 25774b9839 gsm0480: code dup: introduce and use gsm0480_l3hdr_push()
Add function gsm0480_l3hdr_push() to push a struct gsm48_hdr to the start of a
msgb. Use in gsm0480.c and gsm0411_utils.c. Further callers of the new function
will follow in openbsc as well as another libosmocore patch for ussd.

Change-Id: I54fce6053ab8362015686fe22dbcd38bf1366700
2016-12-01 15:54:34 +00:00
Neels Hofmeyr a95ee5e6e1 fix USSD: SS message type mask should be 0x3f, not 0xbf
See 04.80[1], section 3.4: the highest two bits are used as counter or ignored
and do not contribute to the SS "Miscellaneous message group". Previous mask of
0xbf included the highest bit, fix to 0x3f.

Observed a value of 0xbb that should mean 0x3b="Register" during testing of 3G
USSD requests, which seem to be the first to send a nonzero highest bit to our
code. The erratic mask of 0xbf lead to an unhandled message type of 0xbb.

[1] 3GPP TS 24.080 version 7.2.0 Release 7 / ETSI TS 124 080 V7.2.0 (2006-09)

Change-Id: I299001a9e36c16f55622a0acd5d4a55ca49d0055
2016-10-12 09:26:52 +00:00
Neels Hofmeyr 282e908434 04.08: add inline funcs for pdisc + msg type bitmasks
Add inline functions for both release <= 98 and release >= 99 as well as a
default define. Use the release 98 by default since the current code base uses
the r98 bitmasks.

These inline functions relieve callers of the decision on masking bits of the
protocol discriminator and message type octets.

Also add a define for the protocol discriminator extension to one octet length
(GSM48_PDISC_EXTEND).

Apply new pdisc function in gsm0480.c.

[hfreyther: Make the hdr param const]
2016-03-15 14:10:45 +01:00
Tobias Engel 419684e30c Supplementary Services (de)activation, interrogation added
These patches enhance the Supplementary Service (SS) processing from
only being able to handle USSD to other SS, specifically activation,
deactivation and interrogation of those SS. Registration is not yet
implemented.

include/osmocom/gsm/protocol/gsm_09_02.h has been added with needed
values for SS.

Modified by Harald Welte to keep the old ussd-only functiosn for API/ABI
stability.
2015-01-01 14:19:17 +01:00
Alexander Huemer 16ae51eb19 ussd: Fix text of RELEASE COMPLETE
Before the assigned value (0xFF) was truncated, reg->text[0] is of
type char. A corresponding test for the same value in openbsc could
only fail.
2013-10-15 11:50:34 +02:00
Jacob Erlbeck 1d7f3b5eb2 sms: Added result buffer size parameter to 7bit conv funs
The 7bit<->8bit encoding/decoding functions didn't check whether
there is still enough space in the destination buffer. Therefore a
buffer size parameter has been added to each of the functions which
is used to truncate the output if the buffer is too small.

In addition, the return value of the decoding functions has been
changed to number of characters written (excluding \0), so this
value is always equal to strlen(decoded).

The old functions are still available as wrapper functions.
2013-08-12 17:22:27 +02:00
Andreas Eversberg 9597555a36 Add special 7-bit encoding and decoding functions for USSD coding
Handling 7-bit coding is a little different for USSD, as TS 03.38
states:

To avoid the situation where the receiving entity confuses 7 binary
zero pad bits as the @ character, the carriage return or <CR>
character shall be used for padding in this situation [...].

If <CR> is intended to be the last character and the message
(including the wanted <CR>) ends on an octet boundary, then another
<CR> must be added together with a padding bit 0. The receiving entity
will perform the carriage return function twice, but this will not
result in misoperation as the definition of <CR> [...] is identical to
the definition of <CR><CR>.

The receiving entity shall remove the final <CR> character where the
message ends on an octet boundary with <CR> as the last character.

Jacob has verified the fix with fakeBTS and the wireshark dissector.

Fixes: OW#947
Reviewed-by: Jacob Erlbeck <jerlbeck@sysmocom.de>
2013-08-08 14:27:13 +02:00
Holger Hans Peter Freyther 47aa482bb0 gsm: Revert the gsm_7bit_encode changes as they are wrong
This reverts commit f996b05dbd
and 2b0cac4ef8. A detailed
explanation can be found here:

  http://lists.osmocom.org/pipermail/openbsc/2013-July/004737.html

The short description is that:

1.) The API should return (as out parameter) the number of
    octets used.
2.) The handling for the <CR> encoding only applies to USSD
    and it is incomplete. On top of that it broke the SMS test.
2013-07-07 13:59:16 +02:00
Andreas Eversberg 2b0cac4ef8 Fix: Handle returned length by gsm_7bit_encode correctly 2013-07-06 23:36:16 +02:00
Pablo Neira Ayuso 8341934844 include: reorganize headers file to include/osmocom/[gsm|core]
This patch moves all GSM-specific definitions to include/osmocom/gsm.
Moreover, the headers in include/osmocore/ have been moved to
include/osmocom/core.

This has been proposed by Harald Welte and Sylvain Munaunt.

Tested with `make distcheck'.

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:09:28 +01:00
Pablo Neira Ayuso fba495e5f6 This patch moves the GSM-specific functions to the new library
libosmogsm which is provided by libosmocore.

I have also moved generate_backtrace() to backtrace.c instead
of gsm_utils.c, otherwise the timer and msgfile tests depend on
libosmogsm.

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:08:08 +01:00