summaryrefslogtreecommitdiffstats
path: root/src/gsm/gsm_utils.c
Commit message (Collapse)AuthorAgeFilesLines
* gsm: gsm_utils: Fix return type of API ms_class_gmsk_dbm() and add unit testsPau Espin Pedrol2019-11-041-2/+2
| | | | | | | | Only known user of API is in osmocom-bb and it compiles fine after the change. Related: OS#4244 Change-Id: Ia10345008b3aca50b30482ef3b852b03eca71995
* osmo_get_rand_id(): Avoid dead code by proper #if/#else/#endifHarald Welte2019-07-211-1/+2
| | | | | Change-Id: I34e465dead179487f7d4508e0e6ecf0e838c6eb7 Closes: CID#177910
* make all library-internal static buffers thread-localHarald Welte2019-06-041-1/+1
| | | | | | | | | | | | | | | We have a number of library-internal static global buffers which are mainly used for various stringification functions. This worked as all of the related Osmocom programs were strictly single-threaded. Let's make those buffers at least thread-local. This way every thread gets their own set of buffers, and it's safe for multiple threads to execute the same functions once. They're of course still not re-entrant. If you need re-entrancy, you will need to use the _c() or _buf() suffix version of those functions and work with your own (stack or heap) buffers. Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07
* gsm/gsm_utils.c: indicate intentional fall-throughVadim Yanitskiy2019-04-121-0/+1
| | | | | Change-Id: Ica7d2d1884b745fe30234d6c50d93828c4930680 Fixes: CID#57700
* gsm_utils.c: fix Doxygen description for gsm_get_octet_len()Vadim Yanitskiy2019-04-111-4/+4
| | | | Change-Id: Id6fd2cd33be1cb7cd7ff6a43bfcfb1f368304522
* Add _c versions of functions that otherwise return static buffersHarald Welte2019-04-101-0/+7
| | | | | | | | | | | | | | We have a habit of returning static buffers from some functions, particularly when generating some kind of string values. This is convenient in terms of memory management, but it comes at the expense of not being thread-safe, and not allowing for two calls of the related function within one printf() statement. Let's introduce _c suffix versions of those functions where the caller passes in a talloc context from which the output buffer shall be allocated. Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
* gsm_utils: fix use buf_len instead of sizeof in osmo_dump_gsmtime_bufPhilipp Maier2019-04-081-1/+1
| | | | | | | | | | The function osmo_dump_gsmtime_buf gets a pointer *buf and a parameter buf_len. The pointer *buf is a string buffer and the function places an \0 at the end of the buffer before it exists. However it uses sizeof(buf) as part of the index calculation, which is incorrect. Lets correct this by using buf_len instead. Change-Id: Id24263aa7c9a53544f1639b6ceb09ce5615d5114
* Add _buf() functions to bypass static string buffersHarald Welte2019-04-031-4/+9
| | | | | | | | | | | | | | | We have a number of static buffers in use in libosmo*. This means the related functions are not usable in a thread-safe way. While we so far don't have many multi-threaded programs in the osmocom universe, the static buffers also prevent us from calling the same e.g. string-ify function twice within a single printf() call. Let's make sure there's an alternative function in all those cases, where the user can pass in a caller-allocated buffer + size, and make the 'classic' function with the static buffer a wrapper around that _buf() variant. Change-Id: Ibf85f79e93244f53b2684ff6f1095c5b41203e05
* Fix build on non-glibc systemsKarl Koscher2019-03-111-3/+8
| | | | Change-Id: Id5d577522a4889e152158f7e93ee1c99d3a21003
* Automatically disable GnuTLS fallbackMax2019-01-071-0/+1
| | | | | | | | | Disable GnuTLS fallback if sufficient glibc version detected. Previously GnuTLS fallback was used regardless of getrandom() availability in glibc. Fix this by automatically disabling it when not needed. This does not affect the ability to manually disable it unconditionally. Change-Id: Ibe2117afc050261668a4d5a590044aabcd08aefe
* Streamline glibc version checkMax2019-01-071-7/+11
| | | | | | | | | | * use macro for version check * report glibc version upon random.h detection * comment where various #endif belongs to * explicitly check for embedded build (our target toolchain don't use libc so there's no point in checking its version) Change-Id: Ia54f0b7a861f955be65bb0cf06eb10af9372d062
* osmo_rat_type: add OSMO_RAT_EUTRAN_SGSNeels Hofmeyr2019-01-041-0/+1
| | | | | | | osmo-msc is about to implement the SGs interface and requires a RAT indicator for that. Change-Id: I00588396bfe03feba38ecb0717d584594f0b2b46
* gsm_utils: add enum osmo_rat_type, from osmo-msc enum ran_typeNeels Hofmeyr2019-01-031-0/+8
| | | | | | | | | | | | | | | In the MSC, we have RAN types GERAN_A and UTRAN_IU, now we need a similar enum in osmo-hlr's GSUP client. Naming: in the MAP specifications, the RAN type is mostly called RAT type, (Radio Access Network vs. Radio Access Technology?). Since GSUP is more about MAP messages, I'm calling the enum osmo_rat_type. Rationale: osmo-msc and osmo-sgsn want to tell the osmo-hlr which RAT a subscriber is calling on. A subsequent patch will extend the GSUP protocol and add a RAT types IE. Change-Id: I659687aef7a4d67ca372a39fef31dee07aed7631
* gsm: Deprecate buggy gsm_arfcn2band API and introduce gsm_arfcn2band_rcPau Espin Pedrol2018-11-201-23/+48
| | | | | | | | | | | | | | | | | | | ARFCNs are values in well defined ranges. Until this patch, ARFCNs not belonging to any band were blindly assigned to DCS1800 by gsm_arfcn2band, causing unnoticed bugs and misconfigurations in osmo-bsc. Previous API gsm_arfcn2band cannot accomodate this kind of check easily, so let's deprecate it to tell people to use a new API gsm_arfcn2band_rc which performs this kind of checks and allows callers to log failures, misconfigurations, etc. At the same time, modify implementation of gsm_arfcn2band to abort if an invalid ARFCN is passed, this way users of this API can notice they are passing wrong data to it that most probably will produce unexpected results. Related: OS#3063 Change-Id: I780d452dcebce385469e32ef2fd844df6033393a
* gsm_utils: call gnutls_global_init() as constructorAlexander Couzens2018-05-021-0/+19
| | | | | | | | | | gnutls_global_init must be called at least once for gnutls < 3.3.0. It doesn't hurt calling it twice, except a reference counter is increased. gnutls >= 3.3.0 will call it automatic. Fixes: OS#2986 Change-Id: I241b6ae5aa8df13dd78f04658cf0953e9561c9e2
* gsm: Use correct include for getrandomPau Espin Pedrol2017-11-161-1/+1
| | | | | | | | | | | "man getrandom" states sys/random.h is required. Fixes warning below: warning: implicit declaration of function ‘getrandom’; did you mean ‘srandom’? [-Wimplicit-function-declaration] rc = getrandom(out, len, GRND_NONBLOCK); ^~~~~~~~~ Change-Id: I2e73fd018e887893dc5527d6d73644d627eb963a
* Fix/Update copyright notices; Add SPDX annotationHarald Welte2017-11-131-0/+2
| | | | | | | | 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
* Enable GnuTLS fallbackMax2017-11-021-5/+14
| | | | | | | | | | | | | | | | On systems with GNU/Linux kernel older than 3.17 (Debian 8 "jessie" for example) the osmo_get_rand_id() would always return failure due to missing getrandom() syscall. To support such systems, let's add fallback code which uses GnuTLS library. It can be disabled explicitly via '--disable-gnutls' option at compile-time, otherwise ./configure will fail if both getrandom() and GnuTLS are not available. When building with '--enable-embedded' the fallback is disabled automatically. Related: OS#1694 Change-Id: Ic77866ce65acf524b768882c751a4f9c0635740b
* Fix build on older systemsMax2017-10-101-0/+3
| | | | | | | | Make sure GRND_NONBLOCK is always defined, even when using syscall directly. Change-Id: I1bcac37ee1847596b49122f9307bd2689ba71b1b Related: OS#1694
* Add function to generate random identifierMax2017-10-091-0/+48
| | | | | | | | | | | | | | | | | The function is a wrapper on top of getrandom() (if available via glibc) or corresponding syscall. If neither is available than failure is always returned. It's intended to generate small random data good enough for session identifiers and keys. To generate long-term cryptographic keys it's better to use special crypto libraries (like GnuTLS for example) instead. As an example it's used to replace old insecure random number generator in osmo-auc-gen utility. Change-Id: I0241b814ea4c4ce1458f7ad76e31d390383c2048 Related: OS#1694
* utils: add function gsm_fn_as_gsmtime_str()Philipp Maier2017-07-111-0/+11
| | | | | | | Convert a given frame number into a printable string that displays the sub components of the frame number. Change-Id: I8015d2ded3940b01b35df7b72fc35c70c25e9926
* gsm_utils: Add osmo_dump_gsmtimePau Espin Pedrol2017-07-101-0/+11
| | | | | | Used by osmo-bts, moved from osmo-bts l1sap.c:dump_gsmtime. Change-Id: Ib5452e2c20f53006c0f6d197fb055728947125d8
* Fix warnings: tolower() and similar require ucharPau Espin Pedrol2017-06-231-1/+1
| | | | | | | | | | | | utils.c: In function 'osmo_str2lower': utils.c:277:3: warning: array subscript has type 'char' [-Wchar-subscripts] out[i] = tolower(in[i]); And according to man: If c is neither an unsigned char value nor EOF, the behavior of these func‐ tions is undefined. Change-Id: I3fed2ab6a4efba9f8a21fcf84a5b3a91e8df084f
* doxygen: unify use of \file across the boardNeels Hofmeyr2017-06-231-0/+1
| | | | | | | | | | | | | | | | | 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
* doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr2017-06-231-23/+23
| | | | | | | | | | Especially for short descriptions, it is annoying to have to type \brief for every single API doc. Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes the first sentence of an API doc as the brief description. Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
* update/extend doxygen documentationHarald Welte2017-06-121-14/+87
| | | | | | | | | It's a pity that even with this patch we still are fare away from having the whole API documented. However, at least we have a more solid foundation. Updates not only extend the documentation, but also make sure it is rendered properly in the doxygen HTML. Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
* Update doxygen main page for libosmo{core,gsm,vty}Harald Welte2017-06-121-0/+13
| | | | | | | We should link to project homepage as well as put the library into the wider Osmocom context. Change-Id: I07ca57ecef0f36c87c9ebacc1e1507c217bdb25b
* Add function to make Uplink MeasurementMax2016-05-171-0/+20
| | | | | | | | | | | It assembles RSL Uplink Measurement IE according to 3GPP TS 08.58 §9.3.25. The function is based on lchan_build_rsl_ul_meas() from OsmoBTS but optionally includes DTX information. Change-Id: Ib37107bcc9909e5105ea711de42d3fb1db7e8d9e Reviewed-on: https://gerrit.osmocom.org/44 Tested-by: Jenkins Builder Reviewed-by: Harald Welte <laforge@gnumonks.org>
* Add function for appending range1024 to bitvecMax2016-04-231-0/+36
| | | | | Add convenience function to append range1024 encoded data (see 3GPP TS 44.018 Annex J) to a given bitvec.
* Fix sporadic out-of-bounds errorMax2016-01-221-13/+21
| | | | | | | | This code dealing with bit shifting sometimes gets 1 byte beyond array boundary while calculating index. This is now explicitly checked and prevented. Ticket: OW#1198 Sponsored-by: On-Waves ehf
* Add G-RNTI derived TLLI types defined in 23.003Harald Welte2015-08-181-1/+5
|
* sms: Fix gsm_7bit legacy functions return valueJacob Erlbeck2014-01-091-6/+11
| | | | | | | | | | | | | | The legacy 7bit conversion functions (those without the '_n_' in the name) gave wrong return values on 64 bit platforms due to unproper signed/unsigned conversions and the usage of SIZE_MAX. This patch fixes this by using a smaller max size (see GSM_7BIT_LEGACY_MAX_BUFFER_SIZE, currently set to 64k) for the legacy wrappers and by using unsigned int for max_septets. In addition, there are tests now that check the return values of legacy encoding and decoding. Sponsored-by: On-Waves ehf
* sms: Added comment about the gsm_7bit_alphabet tableJacob Erlbeck2013-08-121-2/+6
| | | | | The table structure is not intuitive, so this comment shall aid to understand this.
* sms: Added result buffer size parameter to 7bit conv funsJacob Erlbeck2013-08-121-51/+94
| | | | | | | | | | | | | 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.
* Add special 7-bit encoding and decoding functions for USSD codingAndreas Eversberg2013-08-081-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* encoding: Provide an overload for the gsm_7bit_encode and a simple testHolger Hans Peter Freyther2013-08-081-2/+8
| | | | | | | This is required for encoding the SMS header using the alpha numeric rules. Reviewed-by: Jacob Erlbeck <jerlbeck@sysmocom.de>
* gsm: Revert the gsm_7bit_encode changes as they are wrongHolger Hans Peter Freyther2013-07-071-6/+0
| | | | | | | | | | | | | | | This reverts commit f996b05dbddccb8e8788dd69777a4fedfa2373eb and 2b0cac4ef83137ee0bdd583aee877eac467abeab. 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.
* Fix encoding of last character at 7bit encoding functionAndreas Eversberg2013-07-061-0/+6
| | | | | | 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.
* gsm_utils: refer to ETSI TS 05.08 instead of TS 08.05Bhaskar2013-05-231-2/+2
|
* gsm_septets2octets(): Input parameter should be constHarald Welte2013-03-131-1/+2
|
* gsm: Add method to find ARFCN based on frequencySylvain Munaut2012-12-111-45/+65
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* gsm_utils.c: in 7bit decoding, first check if the last character was an ↵Nico Golde2012-09-211-5/+5
| | | | extension character before doing anything else
* gsm_utils: Fix up coding style in previous patchHarald Welte2012-09-201-2/+2
| | | | 'if' is not a function, so we have space before parenthesis.
* gsm_utils.c: cleanup + do not use dynamic memory when decoding 7bit messagesNico Golde2012-09-201-14/+13
|
* gsm: Address compiler warning about unused variable 'z'Holger Hans Peter Freyther2012-09-111-3/+4
| | | | | | | | The comment explains why we don't care about the content of z, stop storing it. gsm_utils.c: In function 'gsm_7bit_encode': gsm_utils.c:253:13: warning: variable 'z' set but not used [-Wunused-but-set-variable]
* doxygen: Add main page for all three librariesHarald Welte2011-08-301-0/+40
|
* sms: Fix style issues with the code, add spaces after keywordsHolger Hans Peter Freyther2011-07-241-5/+5
|
* sms: SMS where cropped (from VTY), concatenation of SMS where not possibleDennis Wehrle2011-07-241-29/+89
| | | | | | | | | | | | Additionally it wasn't possible to send concatenated sms from the vty. To send multiple sms, it is necessary to use padding bits and add a user_data_header. Therefore the gsm_7bit_encode function was splitted to gsm_7bit_encode and gsm_septets2octets. gsm_septets2octets: this is the old gsm_7bit_encode function + additional padding parameter Additionally the gsm_7bit_decode function was modified to take account for the user_data_header. With the new gsm_get_octet_len function you can get the octet length for a given septet length. I also added several sms tests.
* gsm/utils: Adding conversion of "mobile power class" to dBmAndreas Eversberg2011-06-261-0/+41
| | | | | Written-by: Andreas Eversberg <jolly@eversberg.eu> Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* include: reorganize headers file to include/osmocom/[gsm|core]Pablo Neira Ayuso2011-03-231-3/+3
| | | | | | | | | | | | 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>