summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2010-11-13 22:48:15 +0100
committerSylvain Munaut <tnt@246tNt.com>2010-11-13 22:48:15 +0100
commit11316da173cc0caff14445a159c968ff87204001 (patch)
tree35af21cda48aebb84390601c9b130cf2a480e0b9 /src/shared
parent6f2b172780195e0af780ecd0a4fff0fac9b8438b (diff)
parent7f6615a37df0dadbe86fdfc980e0a8a15013a80e (diff)
Merge commit '7f6615a37df0dadbe86fdfc980e0a8a15013a80e'
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/libosmocore/Makefile.am2
-rw-r--r--src/shared/libosmocore/configure.in2
-rw-r--r--src/shared/libosmocore/include/osmocom/Makefile.am4
-rw-r--r--src/shared/libosmocore/include/osmocom/codec/Makefile.am3
-rw-r--r--src/shared/libosmocore/include/osmocom/codec/codec.h3
-rw-r--r--src/shared/libosmocore/include/osmocore/gsm0808.h3
-rw-r--r--src/shared/libosmocore/include/osmocore/gsm_utils.h1
-rw-r--r--src/shared/libosmocore/include/osmocore/msgb.h23
-rw-r--r--src/shared/libosmocore/include/osmocore/panic.h2
-rw-r--r--src/shared/libosmocore/libosmocodec.pc.in11
-rw-r--r--src/shared/libosmocore/src/gsm0808.c56
-rw-r--r--src/shared/libosmocore/src/gsm_utils.c11
-rw-r--r--src/shared/libosmocore/src/msgfile.c4
-rw-r--r--src/shared/libosmocore/src/panic.c4
-rw-r--r--src/shared/libosmocore/src/select.c5
-rw-r--r--src/shared/libosmocore/tests/msgfile/msgconfig.cfg1
16 files changed, 113 insertions, 22 deletions
diff --git a/src/shared/libosmocore/Makefile.am b/src/shared/libosmocore/Makefile.am
index 81da6294..93254e81 100644
--- a/src/shared/libosmocore/Makefile.am
+++ b/src/shared/libosmocore/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include
SUBDIRS = include src tests
pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libosmocore.pc libosmovty.pc
+pkgconfig_DATA = libosmocore.pc libosmocodec.pc libosmovty.pc
BUILT_SOURCES = $(top_srcdir)/.version
$(top_srcdir)/.version:
diff --git a/src/shared/libosmocore/configure.in b/src/shared/libosmocore/configure.in
index 30f9d9cb..825152d3 100644
--- a/src/shared/libosmocore/configure.in
+++ b/src/shared/libosmocore/configure.in
@@ -99,9 +99,11 @@ AM_CONDITIONAL(ENABLE_MSGFILE, test "x$enable_msgfile" = "x1")
AC_OUTPUT(
libosmocore.pc
+ libosmocodec.pc
libosmovty.pc
include/osmocom/Makefile
include/osmocom/vty/Makefile
+ include/osmocom/codec/Makefile
include/osmocom/crypt/Makefile
include/osmocore/Makefile
include/osmocore/protocol/Makefile
diff --git a/src/shared/libosmocore/include/osmocom/Makefile.am b/src/shared/libosmocore/include/osmocom/Makefile.am
index fd9074cd..ec548fbd 100644
--- a/src/shared/libosmocore/include/osmocom/Makefile.am
+++ b/src/shared/libosmocore/include/osmocom/Makefile.am
@@ -1,5 +1,5 @@
if ENABLE_VTY
-SUBDIRS = vty crypt
+SUBDIRS = vty codec crypt
else
-SUBDIRS = crypt
+SUBDIRS = codec crypt
endif
diff --git a/src/shared/libosmocore/include/osmocom/codec/Makefile.am b/src/shared/libosmocore/include/osmocom/codec/Makefile.am
new file mode 100644
index 00000000..c2136023
--- /dev/null
+++ b/src/shared/libosmocore/include/osmocom/codec/Makefile.am
@@ -0,0 +1,3 @@
+osmocodec_HEADERS = codec.h
+
+osmocodecdir = $(includedir)/osmocom/codec
diff --git a/src/shared/libosmocore/include/osmocom/codec/codec.h b/src/shared/libosmocore/include/osmocom/codec/codec.h
index 82013e55..6f9ffea5 100644
--- a/src/shared/libosmocore/include/osmocom/codec/codec.h
+++ b/src/shared/libosmocore/include/osmocom/codec/codec.h
@@ -4,7 +4,8 @@
#include <stdint.h>
extern uint16_t gsm610_bitorder[]; /* FR */
-extern uint16_t gsm620_bitorder[]; /* HR */
+extern uint16_t gsm620_unvoiced_bitorder[]; /* HR unvoiced */
+extern uint16_t gsm620_voiced_bitorder[]; /* HR voiced */
extern uint16_t gsm660_bitorder[]; /* EFR */
extern uint16_t gsm690_12_2_bitorder[]; /* AMR 12.2 kbits */
diff --git a/src/shared/libosmocore/include/osmocore/gsm0808.h b/src/shared/libosmocore/include/osmocore/gsm0808.h
index 2d609c9e..1d853775 100644
--- a/src/shared/libosmocore/include/osmocore/gsm0808.h
+++ b/src/shared/libosmocore/include/osmocore/gsm0808.h
@@ -26,6 +26,7 @@ struct msgb;
struct msgb *gsm0808_create_layer3(struct msgb *msg, uint16_t netcode, uint16_t countrycode, int lac, uint16_t ci);
struct msgb *gsm0808_create_reset(void);
+struct msgb *gsm0808_create_clear_command(uint8_t reason);
struct msgb *gsm0808_create_clear_complete(void);
struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id);
struct msgb *gsm0808_create_cipher_reject(uint8_t cause);
@@ -35,7 +36,9 @@ struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
uint8_t chosen_channel, uint8_t encr_alg_id,
uint8_t speech_mode);
struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause);
+struct msgb *gsm0808_create_clear_rqst(uint8_t cause);
+struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id);
void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id);
const struct tlv_definition *gsm0808_att_tlvdef();
diff --git a/src/shared/libosmocore/include/osmocore/gsm_utils.h b/src/shared/libosmocore/include/osmocore/gsm_utils.h
index 7dc2388b..0aadd2e4 100644
--- a/src/shared/libosmocore/include/osmocore/gsm_utils.h
+++ b/src/shared/libosmocore/include/osmocore/gsm_utils.h
@@ -87,6 +87,7 @@ static inline int rach_max_trans_raw2val(int raw) {
#define ARFCN_PCS 0x8000
#define ARFCN_UPLINK 0x4000
+#define ARFCN_FLAG_MASK 0xf000 /* Reserve the upper 5 bits for flags */
enum gsm_band gsm_arfcn2band(uint16_t arfcn);
diff --git a/src/shared/libosmocore/include/osmocore/msgb.h b/src/shared/libosmocore/include/osmocore/msgb.h
index 395c7c2c..6fd24c7f 100644
--- a/src/shared/libosmocore/include/osmocore/msgb.h
+++ b/src/shared/libosmocore/include/osmocore/msgb.h
@@ -62,10 +62,11 @@ extern void msgb_reset(struct msgb *m);
#ifdef MSGB_DEBUG
#include <osmocore/panic.h>
-static inline void msgb_abort(struct msgb *msg, const char *text)
-{
- osmo_panic("%s", text);
-}
+#define MSGB_ABORT(msg, fmt, args ...) do { \
+ osmo_panic("msgb(%p): " fmt, msg, ## args); \
+ } while(0)
+#else
+#define MSGB_ABORT(msg, fmt, args ...)
#endif
#define msgb_l1(m) ((void *)(m->l1h))
@@ -106,10 +107,9 @@ static inline int msgb_headroom(const struct msgb *msgb)
static inline unsigned char *msgb_put(struct msgb *msgb, unsigned int len)
{
unsigned char *tmp = msgb->tail;
-#ifdef MSGB_DEBUG
- if (msgb_tailroom(msgb) < len)
- msgb_abort(msgb, "Not enough tailroom\n");
-#endif
+ if (msgb_tailroom(msgb) < (int) len)
+ MSGB_ABORT(msgb, "Not enough tailroom msgb_push (%u < %u)\n",
+ msgb_tailroom(msgb), len);
msgb->tail += len;
msgb->len += len;
return tmp;
@@ -157,10 +157,9 @@ static inline uint32_t msgb_get_u32(struct msgb *msgb)
}
static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len)
{
-#ifdef MSGB_DEBUG
- if (msgb_headroom(msgb) < len)
- msgb_abort(msgb, "Not enough headroom\n");
-#endif
+ if (msgb_headroom(msgb) < (int) len)
+ MSGB_ABORT(msgb, "Not enough headroom msgb_push (%u < %u)\n",
+ msgb_headroom(msgb), len);
msgb->data -= len;
msgb->len += len;
return msgb->data;
diff --git a/src/shared/libosmocore/include/osmocore/panic.h b/src/shared/libosmocore/include/osmocore/panic.h
index cee95358..c5a83778 100644
--- a/src/shared/libosmocore/include/osmocore/panic.h
+++ b/src/shared/libosmocore/include/osmocore/panic.h
@@ -6,6 +6,6 @@
typedef void (*osmo_panic_handler_t)(const char *fmt, va_list args);
void osmo_panic(const char *fmt, ...);
-void osmo_set_panic_handler(osmo_panic_handler_t *h);
+void osmo_set_panic_handler(osmo_panic_handler_t h);
#endif
diff --git a/src/shared/libosmocore/libosmocodec.pc.in b/src/shared/libosmocore/libosmocodec.pc.in
new file mode 100644
index 00000000..3030230b
--- /dev/null
+++ b/src/shared/libosmocore/libosmocodec.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Osmocom Codec related utilities Library
+Description: C Utility Library
+Version: @VERSION@
+Libs: -L${libdir} -losmocodec
+Cflags: -I${includedir}/
+
diff --git a/src/shared/libosmocore/src/gsm0808.c b/src/shared/libosmocore/src/gsm0808.c
index 636c2117..dc450cc4 100644
--- a/src/shared/libosmocore/src/gsm0808.c
+++ b/src/shared/libosmocore/src/gsm0808.c
@@ -108,6 +108,19 @@ struct msgb *gsm0808_create_clear_complete(void)
return msg;
}
+struct msgb *gsm0808_create_clear_command(uint8_t reason)
+{
+ struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
+ "bssmap: clear command");
+ if (!msg)
+ return NULL;
+
+ msg->l3h = msgb_tv_put(msg, BSSAP_MSG_BSS_MANAGEMENT, 4);
+ msgb_v_put(msg, BSS_MAP_MSG_CLEAR_CMD);
+ msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &reason);
+ return msg;
+}
+
struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id)
{
struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
@@ -271,6 +284,26 @@ struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause)
return msg;
}
+struct msgb *gsm0808_create_clear_rqst(uint8_t cause)
+{
+ struct msgb *msg;
+
+ msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
+ "bssmap: clear rqst");
+ if (!msg)
+ return NULL;
+
+ msg->l3h = msgb_put(msg, 2 + 4);
+ msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
+ msg->l3h[1] = 4;
+
+ msg->l3h[2] = BSS_MAP_MSG_CLEAR_RQST;
+ msg->l3h[3] = GSM0808_IE_CAUSE;
+ msg->l3h[4] = 1;
+ msg->l3h[5] = cause;
+ return msg;
+}
+
void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id)
{
uint8_t *hh = msgb_push(msg, 3);
@@ -279,6 +312,29 @@ void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id)
hh[2] = msg->len - 3;
}
+struct msgb *gsm0808_create_dtap(struct msgb *msg_l3, uint8_t link_id)
+{
+ struct dtap_header *header;
+ uint8_t *data;
+ struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
+ "dtap");
+ if (!msg)
+ return NULL;
+
+ /* DTAP header */
+ msg->l3h = msgb_put(msg, sizeof(*header));
+ header = (struct dtap_header *) &msg->l3h[0];
+ header->type = BSSAP_MSG_DTAP;
+ header->link_id = link_id;
+ header->length = msgb_l3len(msg_l3);
+
+ /* Payload */
+ data = msgb_put(msg, header->length);
+ memcpy(data, msg_l3->l3h, header->length);
+
+ return msg;
+}
+
static const struct tlv_definition bss_att_tlvdef = {
.def = {
[GSM0808_IE_IMSI] = { TLV_TYPE_TLV },
diff --git a/src/shared/libosmocore/src/gsm_utils.c b/src/shared/libosmocore/src/gsm_utils.c
index 4b4e2c60..31e3cd69 100644
--- a/src/shared/libosmocore/src/gsm_utils.c
+++ b/src/shared/libosmocore/src/gsm_utils.c
@@ -359,7 +359,11 @@ void generate_backtrace()
enum gsm_band gsm_arfcn2band(uint16_t arfcn)
{
- if (arfcn & ARFCN_PCS)
+ int is_pcs = arfcn & ARFCN_PCS;
+
+ arfcn &= ~ARFCN_FLAG_MASK;
+
+ if (is_pcs)
return GSM_BAND_1900;
else if (arfcn <= 124)
return GSM_BAND_900;
@@ -386,8 +390,11 @@ uint16_t gsm_arfcn2freq10(uint16_t arfcn, int uplink)
{
uint16_t freq10_ul;
uint16_t freq10_dl;
+ int is_pcs = arfcn & ARFCN_PCS;
+
+ arfcn &= ~ARFCN_FLAG_MASK;
- if (arfcn & ARFCN_PCS) {
+ if (is_pcs) {
/* DCS 1900 */
arfcn &= ~ARFCN_PCS;
freq10_ul = 18502 + 2 * (arfcn-512);
diff --git a/src/shared/libosmocore/src/msgfile.c b/src/shared/libosmocore/src/msgfile.c
index 051f5b75..68f05813 100644
--- a/src/shared/libosmocore/src/msgfile.c
+++ b/src/shared/libosmocore/src/msgfile.c
@@ -70,6 +70,10 @@ static void handle_line(struct msg_entries *entries, char *line)
char *items[3];
int last_item = 0;
+ /* Skip comments from the file */
+ if (line[0] == '#')
+ return;
+
for (i = 0; i < len; ++i) {
if (line[i] == '\n' || line[i] == '\r')
line[i] = '\0';
diff --git a/src/shared/libosmocore/src/panic.c b/src/shared/libosmocore/src/panic.c
index a25067de..5fb7b565 100644
--- a/src/shared/libosmocore/src/panic.c
+++ b/src/shared/libosmocore/src/panic.c
@@ -20,6 +20,7 @@
*
*/
+#include <osmocore/gsm_utils.h>
#include <osmocore/panic.h>
#include "../config.h"
@@ -36,6 +37,7 @@ static osmo_panic_handler_t osmo_panic_handler = (void*)0;
static void osmo_panic_default(const char *fmt, va_list args)
{
vfprintf(stderr, fmt, args);
+ generate_backtrace();
abort();
}
@@ -64,7 +66,7 @@ void osmo_panic(const char *fmt, ...)
}
-void osmo_set_panic_handler(osmo_panic_handler_t *h)
+void osmo_set_panic_handler(osmo_panic_handler_t h)
{
osmo_panic_handler = h;
}
diff --git a/src/shared/libosmocore/src/select.c b/src/shared/libosmocore/src/select.c
index f52b0a0c..5aa2beb5 100644
--- a/src/shared/libosmocore/src/select.c
+++ b/src/shared/libosmocore/src/select.c
@@ -5,8 +5,9 @@
* (C) 2000-2009 by Harald Welte <laforge@gnumonks.org>
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation
+ * 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
diff --git a/src/shared/libosmocore/tests/msgfile/msgconfig.cfg b/src/shared/libosmocore/tests/msgfile/msgconfig.cfg
index dfaad299..28d74326 100644
--- a/src/shared/libosmocore/tests/msgfile/msgconfig.cfg
+++ b/src/shared/libosmocore/tests/msgfile/msgconfig.cfg
@@ -1 +1,2 @@
+# This is a comment
*:*::Hello Welt