diff options
author | Sylvain Munaut <tnt@246tNt.com> | 2011-10-21 22:14:52 +0200 |
---|---|---|
committer | Sylvain Munaut <tnt@246tNt.com> | 2011-10-21 22:14:52 +0200 |
commit | 02d469ad67459c8d28c808a19802613a5666364c (patch) | |
tree | 137bf0649440b0f1ac9a72c168c7996484deda91 /src/shared/libosmocore/include | |
parent | 2a64b42111e50d71198bfec1ab28d01e6d1cfd2b (diff) | |
parent | 07f1103782a94090c2cef46de8a3f6d03ddfeef7 (diff) |
Merge commit '07f1103782a94090c2cef46de8a3f6d03ddfeef7'
Diffstat (limited to 'src/shared/libosmocore/include')
17 files changed, 759 insertions, 57 deletions
diff --git a/src/shared/libosmocore/include/osmocom/core/Makefile.am b/src/shared/libosmocore/include/osmocom/core/Makefile.am index f131269d..1df111af 100644 --- a/src/shared/libosmocore/include/osmocom/core/Makefile.am +++ b/src/shared/libosmocore/include/osmocom/core/Makefile.am @@ -2,8 +2,11 @@ osmocore_HEADERS = signal.h linuxlist.h timer.h select.h msgb.h bits.h \ bitvec.h statistics.h utils.h socket.h \ gsmtap.h write_queue.h prim.h \ logging.h rate_ctr.h gsmtap_util.h \ - crc16.h panic.h process.h \ - backtrace.h conv.h application.h + crc16.h panic.h process.h linuxrbtree.h \ + backtrace.h conv.h application.h \ + crcgen.h crc8gen.h crc16gen.h crc32gen.h crc64gen.h + +noinst_HEADERS = timer_compat.h if ENABLE_PLUGIN osmocore_HEADERS += plugin.h @@ -22,3 +25,7 @@ osmocore_HEADERS += serial.h endif osmocoredir = $(includedir)/osmocom/core + +crc%gen.h: crcXXgen.h.tpl + @echo " SED $< -> $@" + @sed -e's/XX/$*/g' $< > $@ diff --git a/src/shared/libosmocore/include/osmocom/core/crcXXgen.h.tpl b/src/shared/libosmocore/include/osmocom/core/crcXXgen.h.tpl new file mode 100644 index 00000000..b411276e --- /dev/null +++ b/src/shared/libosmocore/include/osmocom/core/crcXXgen.h.tpl @@ -0,0 +1,59 @@ +/* + * crcXXgen.h + * + * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __OSMO_CRCXXGEN_H__ +#define __OSMO_CRCXXGEN_H__ + +/*! \addtogroup crcgen + * @{ + */ + +/*! \file crcXXgen.h + * \file Osmocom generic CRC routines (for max XX bits poly) header + */ + + +#include <stdint.h> +#include <osmocom/core/bits.h> + + +/*! \brief structure describing a given CRC code of max XX bits */ +struct osmo_crcXXgen_code { + int bits; /*!< \brief Actual number of bits of the CRC */ + uintXX_t poly; /*!< \brief Polynom (normal representation, MSB omitted */ + uintXX_t init; /*!< \brief Initialization value of the CRC state */ + uintXX_t remainder; /*!< \brief Remainder of the CRC (final XOR) */ +}; + +uintXX_t osmo_crcXXgen_compute_bits(const struct osmo_crcXXgen_code *code, + const ubit_t *in, int len); +int osmo_crcXXgen_check_bits(const struct osmo_crcXXgen_code *code, + const ubit_t *in, int len, const ubit_t *crc_bits); +void osmo_crcXXgen_set_bits(const struct osmo_crcXXgen_code *code, + const ubit_t *in, int len, ubit_t *crc_bits); + + +/*! }@ */ + +#endif /* __OSMO_CRCXXGEN_H__ */ + +/* vim: set syntax=c: */ diff --git a/src/shared/libosmocore/include/osmocom/core/crcgen.h b/src/shared/libosmocore/include/osmocom/core/crcgen.h new file mode 100644 index 00000000..cd916c76 --- /dev/null +++ b/src/shared/libosmocore/include/osmocom/core/crcgen.h @@ -0,0 +1,41 @@ +/* + * crcgen.h + * + * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com> + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __OSMO_CRCGEN_H__ +#define __OSMO_CRCGEN_H__ + +/*! \defgroup crcgen Osmocom generic CRC routines + * @{ + */ + +/*! \file crcgen.h + * \file Osmocom generic CRC routines global header + */ + +#include <osmocom/core/crc8gen.h> +#include <osmocom/core/crc16gen.h> +#include <osmocom/core/crc32gen.h> +#include <osmocom/core/crc64gen.h> + +/*! }@ */ + +#endif /* __OSMO_CRCGEN_H__ */ diff --git a/src/shared/libosmocore/include/osmocom/core/gsmtap.h b/src/shared/libosmocore/include/osmocom/core/gsmtap.h index 236b25ac..dbc3d314 100644 --- a/src/shared/libosmocore/include/osmocom/core/gsmtap.h +++ b/src/shared/libosmocore/include/osmocom/core/gsmtap.h @@ -14,6 +14,21 @@ #include <stdint.h> +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ + +/* The GSMTAP format definition is maintained in libosmocore, + * specifically the latest version can always be obtained from + * http://cgit.osmocom.org/cgit/libosmocore/tree/include/osmocom/core/gsmtap.h + * + * If you want to introduce new protocol/burst/channel types or extend + * GSMTAP in any way, please contact the GSMTAP maintainer at either the + * public openbsc@lists.osmocom.org mailing list, or privately at + * Harald Welte <laforge@gnumonks.org>. + * + * Your cooperation ensures that all projects will use the same GSMTAP + * definitions and remain compatible with each other. + */ + #define GSMTAP_VERSION 0x02 #define GSMTAP_TYPE_UM 0x01 @@ -22,6 +37,12 @@ #define GSMTAP_TYPE_SIM 0x04 #define GSMTAP_TYPE_TETRA_I1 0x05 /* tetra air interface */ #define GSMTAP_TYPE_TETRA_I1_BURST 0x06 /* tetra air interface */ +#define GSMTAP_TYPE_WMX_BURST 0x07 /* WiMAX burst */ +#define GSMTAP_TYPE_GB_LLC 0x08 /* GPRS Gb interface: LLC */ +#define GSMTAP_TYPE_GB_SNDCP 0x09 /* GPRS Gb interface: SNDCP */ +#define GSMTAP_TYPE_GMR1_UM 0x0a /* GMR-1 L2 packets */ + +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ /* sub-types for TYPE_UM_BURST */ #define GSMTAP_BURST_UNKNOWN 0x00 @@ -34,6 +55,15 @@ #define GSMTAP_BURST_DUMMY 0x07 #define GSMTAP_BURST_ACCESS 0x08 #define GSMTAP_BURST_NONE 0x09 +/* WiMAX bursts */ +#define GSMTAP_BURST_CDMA_CODE 0x10 /* WiMAX CDMA Code Attribute burst */ +#define GSMTAP_BURST_FCH 0x11 /* WiMAX FCH burst */ +#define GSMTAP_BURST_FFB 0x12 /* WiMAX Fast Feedback burst */ +#define GSMTAP_BURST_PDU 0x13 /* WiMAX PDU burst */ +#define GSMTAP_BURST_HACK 0x14 /* WiMAX HARQ ACK burst */ +#define GSMTAP_BURST_PHY_ATTRIBUTES 0x15 /* WiMAX PHY Attributes burst */ + +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ /* sub-types for TYPE_UM */ #define GSMTAP_CHANNEL_UNKNOWN 0x00 @@ -47,8 +77,15 @@ #define GSMTAP_CHANNEL_SDCCH8 0x08 #define GSMTAP_CHANNEL_TCH_F 0x09 #define GSMTAP_CHANNEL_TCH_H 0x0a +#define GSMTAP_CHANNEL_CBCH51 0x0b +#define GSMTAP_CHANNEL_CBCH52 0x0c +#define GSMTAP_CHANNEL_PDCH 0x0d +#define GSMTAP_CHANNEL_PTCCH 0x0e +#define GSMTAP_CHANNEL_PACCH 0x0f #define GSMTAP_CHANNEL_ACCH 0x80 +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ + /* sub-types for TYPE_TETRA_AIR */ #define GSMTAP_TETRA_BSCH 0x01 #define GSMTAP_TETRA_AACH 0x02 @@ -59,6 +96,30 @@ #define GSMTAP_TETRA_STCH 0x07 #define GSMTAP_TETRA_TCH_F 0x08 +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ + +/* sub-types for TYPE_GMR1_UM */ +#define GSMTAP_GMR1_UNKNOWN 0x00 +#define GSMTAP_GMR1_BCCH 0x01 +#define GSMTAP_GMR1_CCCH 0x02 /* either AGCH or PCH */ +#define GSMTAP_GMR1_PCH 0x03 +#define GSMTAP_GMR1_AGCH 0x04 +#define GSMTAP_GMR1_BACH 0x05 +#define GSMTAP_GMR1_RACH 0x06 +#define GSMTAP_GMR1_CBCH 0x07 +#define GSMTAP_GMR1_SDCCH 0x08 +#define GSMTAP_GMR1_TACCH 0x09 +#define GSMTAP_GMR1_GBCH 0x0a + +#define GSMTAP_GMR1_SACCH 0x01 /* to be combined with _TCH{6,9} */ +#define GSMTAP_GMR1_FACCH 0x02 /* to be combines with _TCH{3,6,9} */ +#define GSMTAP_GMR1_DKAB 0x03 /* to be combined with _TCH3 */ +#define GSMTAP_GMR1_TCH3 0x10 +#define GSMTAP_GMR1_TCH6 0x14 +#define GSMTAP_GMR1_TCH9 0x18 + +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ + /* flags for the ARFCN */ #define GSMTAP_ARFCN_F_PCS 0x8000 #define GSMTAP_ARFCN_F_UPLINK 0x4000 @@ -67,6 +128,7 @@ /* IANA-assigned well-known UDP port for GSMTAP messages */ #define GSMTAP_UDP_PORT 4729 +/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */ struct gsmtap_hdr { uint8_t version; /* version, set to 0x01 currently */ uint8_t hdr_len; /* length in number of 32bit words */ diff --git a/src/shared/libosmocore/include/osmocom/core/gsmtap_util.h b/src/shared/libosmocore/include/osmocom/core/gsmtap_util.h index 36cbf532..5609381f 100644 --- a/src/shared/libosmocore/include/osmocom/core/gsmtap_util.h +++ b/src/shared/libosmocore/include/osmocom/core/gsmtap_util.h @@ -12,6 +12,10 @@ uint8_t chantype_rsl2gsmtap(uint8_t rsl_chantype, uint8_t rsl_link_id); +struct msgb *gsmtap_makemsg_ex(uint8_t type, uint16_t arfcn, uint8_t ts, uint8_t chan_type, + uint8_t ss, uint32_t fn, int8_t signal_dbm, + uint8_t snr, const uint8_t *data, unsigned int len); + struct msgb *gsmtap_makemsg(uint16_t arfcn, uint8_t ts, uint8_t chan_type, uint8_t ss, uint32_t fn, int8_t signal_dbm, uint8_t snr, const uint8_t *data, unsigned int len); @@ -40,6 +44,11 @@ int gsmtap_source_add_sink(struct gsmtap_inst *gti); int gsmtap_sendmsg(struct gsmtap_inst *gti, struct msgb *msg); +int gsmtap_send_ex(struct gsmtap_inst *gti, uint8_t type, uint16_t arfcn, uint8_t ts, + uint8_t chan_type, uint8_t ss, uint32_t fn, + int8_t signal_dbm, uint8_t snr, const uint8_t *data, + unsigned int len); + int gsmtap_send(struct gsmtap_inst *gti, uint16_t arfcn, uint8_t ts, uint8_t chan_type, uint8_t ss, uint32_t fn, int8_t signal_dbm, uint8_t snr, const uint8_t *data, diff --git a/src/shared/libosmocore/include/osmocom/core/linuxrbtree.h b/src/shared/libosmocore/include/osmocom/core/linuxrbtree.h new file mode 100644 index 00000000..ee988918 --- /dev/null +++ b/src/shared/libosmocore/include/osmocom/core/linuxrbtree.h @@ -0,0 +1,160 @@ +/* + Red Black Trees + (C) 1999 Andrea Arcangeli <andrea@suse.de> + + This program is free software; you can redistribute it and/or modify + 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 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + linux/include/linux/rbtree.h + + To use rbtrees you'll have to implement your own insert and search cores. + This will avoid us to use callbacks and to drop drammatically performances. + I know it's not the cleaner way, but in C (not in C++) to get + performances and genericity... + + Some example of insert and search follows here. The search is a plain + normal search over an ordered tree. The insert instead must be implemented + int two steps: as first thing the code must insert the element in + order as a red leaf in the tree, then the support library function + rb_insert_color() must be called. Such function will do the + not trivial work to rebalance the rbtree if necessary. + +----------------------------------------------------------------------- +static inline struct page * rb_search_page_cache(struct inode * inode, + unsigned long offset) +{ + struct rb_node * n = inode->i_rb_page_cache.rb_node; + struct page * page; + + while (n) + { + page = rb_entry(n, struct page, rb_page_cache); + + if (offset < page->offset) + n = n->rb_left; + else if (offset > page->offset) + n = n->rb_right; + else + return page; + } + return NULL; +} + +static inline struct page * __rb_insert_page_cache(struct inode * inode, + unsigned long offset, + struct rb_node * node) +{ + struct rb_node ** p = &inode->i_rb_page_cache.rb_node; + struct rb_node * parent = NULL; + struct page * page; + + while (*p) + { + parent = *p; + page = rb_entry(parent, struct page, rb_page_cache); + + if (offset < page->offset) + p = &(*p)->rb_left; + else if (offset > page->offset) + p = &(*p)->rb_right; + else + return page; + } + + rb_link_node(node, parent, p); + + return NULL; +} + +static inline struct page * rb_insert_page_cache(struct inode * inode, + unsigned long offset, + struct rb_node * node) +{ + struct page * ret; + if ((ret = __rb_insert_page_cache(inode, offset, node))) + goto out; + rb_insert_color(node, &inode->i_rb_page_cache); + out: + return ret; +} +----------------------------------------------------------------------- +*/ + +#ifndef _LINUX_RBTREE_H +#define _LINUX_RBTREE_H + +#include <stdlib.h> + +struct rb_node +{ + unsigned long rb_parent_color; +#define RB_RED 0 +#define RB_BLACK 1 + struct rb_node *rb_right; + struct rb_node *rb_left; +} __attribute__((aligned(sizeof(long)))); + /* The alignment might seem pointless, but allegedly CRIS needs it */ + +struct rb_root +{ + struct rb_node *rb_node; +}; + + +#define rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3)) +#define rb_color(r) ((r)->rb_parent_color & 1) +#define rb_is_red(r) (!rb_color(r)) +#define rb_is_black(r) rb_color(r) +#define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0) +#define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0) + +static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p) +{ + rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p; +} +static inline void rb_set_color(struct rb_node *rb, int color) +{ + rb->rb_parent_color = (rb->rb_parent_color & ~1) | color; +} + +#define RB_ROOT { NULL, } +#define rb_entry(ptr, type, member) container_of(ptr, type, member) + +#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL) +#define RB_EMPTY_NODE(node) (rb_parent(node) == node) +#define RB_CLEAR_NODE(node) (rb_set_parent(node, node)) + +extern void rb_insert_color(struct rb_node *, struct rb_root *); +extern void rb_erase(struct rb_node *, struct rb_root *); + +/* Find logical next and previous nodes in a tree */ +extern struct rb_node *rb_next(struct rb_node *); +extern struct rb_node *rb_prev(struct rb_node *); +extern struct rb_node *rb_first(struct rb_root *); +extern struct rb_node *rb_last(struct rb_root *); + +/* Fast replacement of a single node without remove/rebalance/add/rebalance */ +extern void rb_replace_node(struct rb_node *victim, struct rb_node *new, + struct rb_root *root); + +static inline void rb_link_node(struct rb_node * node, struct rb_node * parent, + struct rb_node ** rb_link) +{ + node->rb_parent_color = (unsigned long )parent; + node->rb_left = node->rb_right = NULL; + + *rb_link = node; +} + +#endif /* _LINUX_RBTREE_H */ diff --git a/src/shared/libosmocore/include/osmocom/core/logging.h b/src/shared/libosmocore/include/osmocom/core/logging.h index 72e4c93e..b207c1b4 100644 --- a/src/shared/libosmocore/include/osmocom/core/logging.h +++ b/src/shared/libosmocore/include/osmocom/core/logging.h @@ -62,7 +62,7 @@ void logp(int subsys, char *file, int line, int cont, const char *format, ...) _ /* logging levels defined by the library itself */ #define DLGLOBAL -1 -#define DLLAPDM -2 +#define DLLAPD -2 #define DLINP -3 #define DLMUX -4 #define DLMI -5 diff --git a/src/shared/libosmocore/include/osmocom/core/prim.h b/src/shared/libosmocore/include/osmocom/core/prim.h index 2e60c46d..b1026fe3 100644 --- a/src/shared/libosmocore/include/osmocom/core/prim.h +++ b/src/shared/libosmocore/include/osmocom/core/prim.h @@ -10,6 +10,9 @@ #include <stdint.h> #include <osmocom/core/msgb.h> +#define OSMO_PRIM(prim, op) ((prim << 8) | (op & 0xFF)) +#define OSMO_PRIM_HDR(oph) OSMO_PRIM((oph)->primitive, (oph)->operation) + /*! \brief primitive operation */ enum osmo_prim_operation { PRIM_OP_REQUEST, /*!< \brief request */ diff --git a/src/shared/libosmocore/include/osmocom/core/timer.h b/src/shared/libosmocore/include/osmocom/core/timer.h index 8f8c826d..30f558b4 100644 --- a/src/shared/libosmocore/include/osmocom/core/timer.h +++ b/src/shared/libosmocore/include/osmocom/core/timer.h @@ -32,6 +32,7 @@ #include <sys/time.h> #include <osmocom/core/linuxlist.h> +#include <osmocom/core/linuxrbtree.h> /** * Timer management: @@ -51,11 +52,10 @@ */ /*! \brief A structure representing a single instance of a timer */ struct osmo_timer_list { - struct llist_head entry; /*!< \brief linked list header */ + struct rb_node node; /*!< \brief rb-tree node header */ + struct llist_head list; /*!< \brief internal list header */ struct timeval timeout; /*!< \brief expiration time */ unsigned int active : 1; /*!< \brief is it active? */ - unsigned int handled : 1; /*!< \brief did we already handle it */ - unsigned int in_list : 1; /*!< \brief is it in the global list? */ void (*cb)(void*); /*!< \brief call-back called at timeout */ void *data; /*!< \brief user data for callback */ diff --git a/src/shared/libosmocore/include/osmocom/core/timer_compat.h b/src/shared/libosmocore/include/osmocom/core/timer_compat.h new file mode 100644 index 00000000..209e84a3 --- /dev/null +++ b/src/shared/libosmocore/include/osmocom/core/timer_compat.h @@ -0,0 +1,79 @@ +/* + * (C) 2011 Sylvain Munaut <tnt@246tNt.com> + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +/*! \defgroup timer Osmocom timers + * @{ + */ + +/*! \file timer_compat.h + * \brief Compatibility header with some helpers + */ + +#ifndef TIMER_COMPAT_H +#define TIMER_COMPAT_H + + +/* Convenience macros for operations on timevals. + NOTE: `timercmp' does not work for >= or <=. */ + +#ifndef timerisset +# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#endif + +#ifndef timerclear +# define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#endif + +#ifndef timercmp +# define timercmp(a, b, CMP) \ + (((a)->tv_sec == (b)->tv_sec) ? \ + ((a)->tv_usec CMP (b)->tv_usec) : \ + ((a)->tv_sec CMP (b)->tv_sec)) +#endif + +#ifndef timeradd +# define timeradd(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ + if ((result)->tv_usec >= 1000000) \ + { \ + ++(result)->tv_sec; \ + (result)->tv_usec -= 1000000; \ + } \ + } while (0) +#endif + +#ifndef timersub +# define timersub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ + } while (0) +#endif + + +/*! }@ */ + +#endif /* TIMER_COMPAT_H */ diff --git a/src/shared/libosmocore/include/osmocom/gsm/Makefile.am b/src/shared/libosmocore/include/osmocom/gsm/Makefile.am index 90f19bc5..5971d0c5 100644 --- a/src/shared/libosmocore/include/osmocom/gsm/Makefile.am +++ b/src/shared/libosmocore/include/osmocom/gsm/Makefile.am @@ -1,6 +1,6 @@ osmogsm_HEADERS = a5.h comp128.h gsm0808.h gsm48_ie.h mncc.h rxlev_stat.h \ gsm0480.h gsm48.h gsm_utils.h rsl.h tlv.h abis_nm.h \ - sysinfo.h prim.h gsm0502.h lapdm.h + sysinfo.h prim.h gsm0502.h lapd_core.h lapdm.h SUBDIRS = protocol diff --git a/src/shared/libosmocore/include/osmocom/gsm/lapd_core.h b/src/shared/libosmocore/include/osmocom/gsm/lapd_core.h new file mode 100644 index 00000000..0f4e8899 --- /dev/null +++ b/src/shared/libosmocore/include/osmocom/gsm/lapd_core.h @@ -0,0 +1,171 @@ +#ifndef _OSMOCOM_LAPD_H +#define _OSMOCOM_LAPD_H + +#include <stdint.h> + +#include <osmocom/core/timer.h> +#include <osmocom/core/msgb.h> +#include <osmocom/gsm/prim.h> + +/*! \defgroup lapd LAPD implementation common part + * @{ + */ + +/*! \file lapd.h */ + +/* primitive related sutff */ + +/*! \brief LAPD related primitives (L2<->L3 SAP)*/ +enum osmo_dl_prim { + PRIM_DL_UNIT_DATA, /*!< \brief DL-UNIT-DATA */ + PRIM_DL_DATA, /*!< \brief DL-DATA */ + PRIM_DL_EST, /*!< \brief DL-ESTABLISH */ + PRIM_DL_REL, /*!< \brief DL-RLEEASE */ + PRIM_DL_SUSP, /*!< \brief DL-SUSPEND */ + PRIM_DL_RES, /*!< \brief DL-RESUME */ + PRIM_DL_RECON, /*!< \brief DL-RECONNECT */ + PRIM_MDL_ERROR, /*!< \brief MDL-ERROR */ +}; + +/* Uses the same values as RLL, so no conversion for GSM is required. */ +#define MDL_CAUSE_T200_EXPIRED 0x01 +#define MDL_CAUSE_REEST_REQ 0x02 +#define MDL_CAUSE_UNSOL_UA_RESP 0x03 +#define MDL_CAUSE_UNSOL_DM_RESP 0x04 +#define MDL_CAUSE_UNSOL_DM_RESP_MF 0x05 +#define MDL_CAUSE_UNSOL_SPRV_RESP 0x06 +#define MDL_CAUSE_SEQ_ERR 0x07 +#define MDL_CAUSE_UFRM_INC_PARAM 0x08 +#define MDL_CAUSE_SFRM_INC_PARAM 0x09 +#define MDL_CAUSE_IFRM_INC_MBITS 0x0a +#define MDL_CAUSE_IFRM_INC_LEN 0x0b +#define MDL_CAUSE_FRM_UNIMPL 0x0c +#define MDL_CAUSE_SABM_MF 0x0d +#define MDL_CAUSE_SABM_INFO_NOTALL 0x0e +#define MDL_CAUSE_FRMR 0x0f + +/*! \brief for MDL-ERROR.ind */ +struct mdl_error_ind_param { + uint8_t cause; /*!< \brief generic cause value */ +}; + +/*! \brief for DL-REL.req */ +struct dl_rel_req_param { + uint8_t mode; /*!< \brief release mode */ +}; + +/*! \brief primitive header for LAPD DL-SAP primitives */ +struct osmo_dlsap_prim { + struct osmo_prim_hdr oph; /*!< \brief generic primitive header */ + union { + struct mdl_error_ind_param error_ind; + struct dl_rel_req_param rel_req; + } u; /*!< \brief request-specific data */ +}; + +/*! \brief LAPD mode/role */ +enum lapd_mode { + LAPD_MODE_USER, /*!< \brief behave like user */ + LAPD_MODE_NETWORK, /*!< \brief behave like network */ +}; + +/*! \brief LAPD state (Figure B.2/Q.921)*/ +enum lapd_state { + LAPD_STATE_NULL = 0, + LAPD_STATE_TEI_UNASS, + LAPD_STATE_ASS_TEI_WAIT, + LAPD_STATE_EST_TEI_WAIT, + LAPD_STATE_IDLE, + LAPD_STATE_SABM_SENT, + LAPD_STATE_DISC_SENT, + LAPD_STATE_MF_EST, + LAPD_STATE_TIMER_RECOV, +}; + +/*! \brief LAPD message format (I / S / U) */ +enum lapd_format { + LAPD_FORM_UKN = 0, + LAPD_FORM_I, + LAPD_FORM_S, + LAPD_FORM_U, +}; + +/*! \brief LAPD message context */ +struct lapd_msg_ctx { + struct lapd_datalink *dl; + int n201; + /* address */ + uint8_t cr; + uint8_t sapi; + uint8_t tei; + uint8_t lpd; + /* control */ + uint8_t format; + uint8_t p_f; /* poll / final bit */ + uint8_t n_send; + uint8_t n_recv; + uint8_t s_u; /* S or repectivly U function bits */ + /* length */ + int length; + uint8_t more; +}; + +struct lapd_cr_ent { + uint8_t cmd; + uint8_t resp; +}; + +struct lapd_history { + struct msgb *msg; /* message to be sent / NULL, if histoy is empty */ + int more; /* if message is fragmented */ +}; + +/*! \brief LAPD datalink */ +struct lapd_datalink { + int (*send_dlsap)(struct osmo_dlsap_prim *dp, + struct lapd_msg_ctx *lctx); + int (*send_ph_data_req)(struct lapd_msg_ctx *lctx, struct msgb *msg); + struct { + /*! \brief filled-in once we set the lapd_mode above */ + struct lapd_cr_ent loc2rem; + struct lapd_cr_ent rem2loc; + } cr; + enum lapd_mode mode; /*!< \brief current mode of link */ + int use_sabme; /*!< \brief use SABME instead of SABM */ + int reestablish; /*!< \brief enable reestablish support */ + int n200, n200_est_rel; /*!< \brief number of retranmissions */ + struct lapd_msg_ctx lctx; /*!< \brief LAPD context */ + int maxf; /*!< \brief maximum frame size (after defragmentation) */ + uint8_t k; /*!< \brief maximum number of unacknowledged frames */ + uint8_t v_range; /*!< \brief range of sequence numbers */ + uint8_t v_send; /*!< \brief seq nr of next I frame to be transmitted */ + uint8_t v_ack; /*!< \brief last frame ACKed by peer */ + uint8_t v_recv; /*!< \brief seq nr of next I frame expected to be received */ + uint32_t state; /*!< \brief LAPD state (\ref lapd_state) */ + int seq_err_cond; /*!< \brief condition of sequence error */ + uint8_t own_busy; /*!< \brief receiver busy on our side */ + uint8_t peer_busy; /*!< \brief receiver busy on remote side */ + int t200_sec, t200_usec; /*!< \brief retry timer (default 1 sec) */ + int t203_sec, t203_usec; /*!< \brief retry timer (default 10 secs) */ + struct osmo_timer_list t200; /*!< \brief T200 timer */ + struct osmo_timer_list t203; /*!< \brief T203 timer */ + uint8_t retrans_ctr; /*!< \brief re-transmission counter */ + struct llist_head tx_queue; /*!< \brief frames to L1 */ + struct llist_head send_queue; /*!< \brief frames from L3 */ + struct msgb *send_buffer; /*!< \brief current frame transmitting */ + int send_out; /*!< \brief how much was sent from send_buffer */ + struct lapd_history *tx_hist; /*!< \brief tx history structure array */ + uint8_t range_hist; /*!< \brief range of history buffer 2..2^n */ + struct msgb *rcv_buffer; /*!< \brief buffer to assemble the received message */ + struct msgb *cont_res; /*!< \brief buffer to store content resolution data on network side, to detect multiple phones on same channel */ +}; + +void lapd_dl_init(struct lapd_datalink *dl, uint8_t k, uint8_t v_range, + int maxf); +void lapd_dl_exit(struct lapd_datalink *dl); +void lapd_dl_reset(struct lapd_datalink *dl); +int lapd_set_mode(struct lapd_datalink *dl, enum lapd_mode mode); +int lapd_ph_data_ind(struct msgb *msg, struct lapd_msg_ctx *lctx); +int lapd_recv_dlsap(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx); + +#endif /* _OSMOCOM_LAPD_H */ diff --git a/src/shared/libosmocore/include/osmocom/gsm/lapdm.h b/src/shared/libosmocore/include/osmocom/gsm/lapdm.h index b71feef1..cc9c63fe 100644 --- a/src/shared/libosmocore/include/osmocom/gsm/lapdm.h +++ b/src/shared/libosmocore/include/osmocom/gsm/lapdm.h @@ -1,11 +1,7 @@ #ifndef _OSMOCOM_LAPDM_H #define _OSMOCOM_LAPDM_H -#include <stdint.h> - -#include <osmocom/core/timer.h> -#include <osmocom/core/msgb.h> -#include <osmocom/gsm/prim.h> +#include <osmocom/gsm/lapd_core.h> /*! \defgroup lapdm LAPDm implementation according to GSM TS 04.06 * @{ @@ -15,7 +11,7 @@ /* primitive related sutff */ -/*! \brief LAPDm related primitives */ +/*! \brief LAPDm related primitives (L1<->L2 SAP) */ enum osmo_ph_prim { PRIM_PH_DATA, /*!< \brief PH-DATA */ PRIM_PH_RACH, /*!< \brief PH-RANDOM_ACCESS */ @@ -68,52 +64,22 @@ enum lapdm_mode { LAPDM_MODE_BTS, /*!< \brief behave like a BTS (network) */ }; -/*! \brief LAPDm state */ -enum lapdm_state { - LAPDm_STATE_NULL = 0, - LAPDm_STATE_IDLE, - LAPDm_STATE_SABM_SENT, - LAPDm_STATE_MF_EST, - LAPDm_STATE_TIMER_RECOV, - LAPDm_STATE_DISC_SENT, -}; - struct lapdm_entity; /*! \brief LAPDm message context */ struct lapdm_msg_ctx { struct lapdm_datalink *dl; int lapdm_fmt; - uint8_t n201; uint8_t chan_nr; uint8_t link_id; - uint8_t addr; - uint8_t ctrl; uint8_t ta_ind; uint8_t tx_power_ind; }; /*! \brief LAPDm datalink like TS 04.06 / Section 3.5.2 */ struct lapdm_datalink { - uint8_t V_send; /*!< \brief seq nr of next I frame to be transmitted */ - uint8_t V_ack; /*!< \brief last frame ACKed by peer */ - uint8_t N_send; /*!< \brief ? set to V_send at Tx time*/ - uint8_t V_recv; /*!< \brief seq nr of next I frame expected to be received */ - uint8_t N_recv; /*!< \brief expected send seq nr of the next received I frame */ - uint32_t state; /*!< \brief LAPDm state (\ref lapdm_state) */ - int seq_err_cond; /*!< \brief condition of sequence error */ - uint8_t own_busy; /*!< \brief receiver busy on our side */ - uint8_t peer_busy; /*!< \brief receiver busy on remote side */ - struct osmo_timer_list t200; /*!< \brief T200 timer */ - uint8_t retrans_ctr; /*!< \brief re-transmission counter */ - struct llist_head send_queue; /*!< \brief frames from L3 */ - struct msgb *send_buffer; /*!< \brief current frame transmitting */ - int send_out; /*!< \brief how much was sent from send_buffer */ - uint8_t tx_hist[8][200]; /*!< \brief tx history buffer */ - int tx_length[8]; /*!< \brief length in history buffer */ - struct llist_head tx_queue; /*!< \brief frames to L1 */ + struct lapd_datalink dl; /* \brief common LAPD */ struct lapdm_msg_ctx mctx; /*!< \brief context of established connection */ - struct msgb *rcv_buffer; /*!< \brief buffer to assemble the received message */ struct lapdm_entity *entity; /*!< \brief LAPDm entity we are part of */ }; @@ -127,11 +93,6 @@ enum lapdm_dl_sapi { typedef int (*lapdm_cb_t)(struct msgb *msg, struct lapdm_entity *le, void *ctx); -struct lapdm_cr_ent { - uint8_t cmd; - uint8_t resp; -}; - #define LAPDM_ENT_F_EMPTY_FRAME 0x0001 #define LAPDM_ENT_F_POLLING_ONLY 0x0002 @@ -144,12 +105,6 @@ struct lapdm_entity { enum lapdm_mode mode; /*!< \brief are we in BTS mode or MS mode */ unsigned int flags; - struct { - /*! \brief filled-in once we set the lapdm_mode above */ - struct lapdm_cr_ent loc2rem; - struct lapdm_cr_ent rem2loc; - } cr; - void *l1_ctx; /*!< \brief context for layer1 instance */ void *l3_ctx; /*!< \brief context for layer3 instance */ diff --git a/src/shared/libosmocore/include/osmocom/gsm/protocol/Makefile.am b/src/shared/libosmocore/include/osmocom/gsm/protocol/Makefile.am index 7f6de639..6ed55e46 100644 --- a/src/shared/libosmocore/include/osmocom/gsm/protocol/Makefile.am +++ b/src/shared/libosmocore/include/osmocom/gsm/protocol/Makefile.am @@ -1,6 +1,6 @@ osmogsm_proto_HEADERS = gsm_03_41.h \ gsm_04_08.h gsm_04_11.h gsm_04_12.h gsm_04_80.h \ - gsm_08_08.h gsm_08_58.h \ + gsm_08_08.h gsm_08_58.h gsm_44_318.h \ gsm_12_21.h ipaccess.h osmogsm_protodir = $(includedir)/osmocom/gsm/protocol diff --git a/src/shared/libosmocore/include/osmocom/gsm/protocol/gsm_44_318.h b/src/shared/libosmocore/include/osmocom/gsm/protocol/gsm_44_318.h new file mode 100644 index 00000000..31c0ea7c --- /dev/null +++ b/src/shared/libosmocore/include/osmocom/gsm/protocol/gsm_44_318.h @@ -0,0 +1,153 @@ +#ifndef PROTO_GSM_44_318_H +#define PROTO_GSM_44_318_H + +#include <stdint.h> + +/* Definitions according to 3GPP TS 44.318 6.8.0 Release 6 */ + +/* Table 11.1.1.4.1: Message types for URR */ + +enum gan_msg_type { + GA_MT_RC_DISCOVERY_REQUEST = 0x01, + GA_MT_RC_DISCOVERY_ACCEPT = 0x02, + GA_MT_RC_DISCOVERY_REJECT = 0x03, + + GA_MT_RC_REGISTER_REQUEST = 0x10, + GA_MT_RC_REGISTER_ACCEPT = 0x11, + GA_MT_RC_REGISTER_REDIRECT = 0x12, + GA_MT_RC_REGISTER_REJECT = 0x13, + GA_MT_RC_DEREGISTER = 0x14, + GA_MT_RC_REGISTER_UPDATE_UL = 0x15, + GA_MT_RC_REGISTER_UPDATE_DL = 0x16, + GA_MT_RC_CELL_BCAST_INFO = 0x17, + + GA_MT_CSR_CIPH_MODE_CMD = 0x20, + GA_MT_CSR_CIPH_MODE_COMPL = 0x21, + + GA_MT_CSR_ACT_CHAN = 0x30, + GA_MT_CSR_ACT_CHAN_ACK = 0x31, + GA_MT_CSR_ACT_CHAN_COMPL = 0x32, + GA_MT_CSR_ACT_CHAN_FAIL = 0x33, + GA_MT_CSR_CHAN_MODE_MOD = 0x34, + GA_MT_CSR_CHAN_MODE_MOD_ACK = 0x35, + + GA_MT_CSR_RELEASE = 0x40, + GA_MT_CSR_RELEASE_COMPL = 0x41, + GA_MT_CSR_CLEAR_REQ = 0x42, + + GA_MT_CSR_HO_ACCESS = 0x50, + GA_MT_CSR_HO_COMPL = 0x51, + GA_MT_CSR_UL_QUAL_IND = 0x52, + GA_MT_CSR_HO_INFO = 0x53, + GA_MT_CSR_HO_CMD = 0x54, + GA_MT_CSR_HO_FAIL = 0x55, + + GA_MT_CSR_PAGING_REQ = 0x60, + GA_MT_CSR_PAGING_RESP = 0x61, + + GA_MT_CSR_UL_DIRECT_XFER = 0x70, + GA_MT_CSR_DL_DIRECT_XFER = 0x72, + GA_MT_CSR_STATUS = 0x73, + GA_MT_RC_KEEPALIVE = 0x74, + GA_MT_CSR_CM_ENQ = 0x75, + GA_MT_CSR_CM_CHANGE = 0x76, + + GA_MT_CSR_REQUEST = 0x80, + GA_MT_CSR_REQUEST_ACCEPT = 0x81, + GA_MT_CSR_REQUEST_REJECT = 0x82, +}; + +/* All tables in 10.1.x and 10.2.x / Table 11.2.1 */ +enum gan_iei { + GA_IE_MI = 1, + GA_IE_GAN_RELEASE_IND = 2, + GA_IE_RADIO_IE = 3, + GA_IE_GERAN_CELL_ID = 4, + GA_IE_LAC = 5, + GA_IE_GERAN_COV_IND = 6, + GA_IE_GAN_CM = 7, + GA_IE_GEO_LOC = 8, + GA_IE_DEF_SEGW_IP = 9, + GA_IE_DEF_SEGW_FQDN = 10, + GA_IE_REDIR_CTR = 11, + GA_IE_DISCOV_REJ_CAUSE = 12, + GA_IE_GANC_CELL_DESC = 13, + GA_IE_GANC_CTRL_CH_DESC = 14, + GA_IE_GERAN_CELL_ID_LIST= 15, + GA_IE_TU3907_TIMER = 16, + GA_IE_RR_STATE = 17, + GA_IE_RAI = 18, + GA_IE_GAN_BAND = 19, + GA_IE_GARC_GACSR_STATE = 20, + GA_IE_REG_REJ_CAUSE = 21, + GA_IE_TU3906_TIMER = 22, + GA_IE_TU3910_TIMER = 23, + GA_IE_TU3902_TIMER = 24, + GA_IE_L3_MSG = 26, + GA_IE_CHAN_MODE = 27, + GA_IE_MS_CLASSMARK2 = 28, + GA_IE_RR_CAUSE = 29, + GA_EI_CIPH_MODE_SET = 30, + GA_IE_GPRS_RESUMPTION = 31, + GA_IE_HO_FROM_GAN_CMD = 32, + GA_IE_UL_QUAL_IND = 33, + GA_IE_TLLI = 34, + GA_IE_PFI = 35, + GA_IE_SUSP_CAUSE = 36, + GA_IE_TU3820_TIMER = 37, + GA_IE_REQD_QOS = 38, + GA_IE_P_DEACT_CAUSE = 39 + GA_IE_REQD_UL_RATE = 40, + GA_IE_RAC = 41, + GA_IE_AP_LOCATION = 42, + GA_IE_TU4001_TIMER = 43, + GA_IE_LOC_STATUS = 44, + GA_IE_CIPH_RESP = 45, + GA_IE_CIPH_RAND = 46, + GA_IE_CIPH_MAC = 47, + GA_IE_CKSN = 48, + GA_IE_SAPI_ID = 49, + GA_IE_EST_CAUSE = 50, + GA_IE_CHAN_NEEDED = 51, + GA_IE_PDU_IN_ERROR = 52, + GA_IE_SAMPLE_SIZE = 53, + GA_IE_PAYLOAD_TYPE = 54, + GA_IE_MULTIRATE_CONF = 55, + GA_IE_MS_CLASSMARK3 = 56, + GA_IE_LLC_PDU = 57, + GA_IE_LOC_BLACKL_IND = 58, + GA_IE_RESET_IND = 59, + GA_IE_TU4003_TIMER = 60, + GA_IE_AP_SERV_NAME = 61, + GA_IE_SERV_ZONE_INFO = 62, + GA_IE_RTP_RED_CONF = 63, + GA_IE_UTRAN_CLASSMARK = 64, + GA_IE_CM_ENQ_MASK = 65, + GA_IE_UTRAN_CELLID_LIST = 66, + GA_IE_SERV_GANC_TBL_IND = 67, + GA_IE_AP_REG_IND = 68, + GA_IE_GAN_PLMN_LIST = 69, + GA_IE_REQD_GAN_SERV = 71, + GA_IE_BCAST_CONTAINER = 72, + GA_IE_3G_CELL_ID = 73, + GA_IE_MS_RADIO_ID = 96, + GA_IE_DEF_GANC_IP = 97, + GA_IE_DEF_GANC_FQDN = 98, + GA_IE_GPRS_IP_ADDR = 99, + GA_IE_GPRS_UDP_PORT = 100 + GA_IE_GANC_TCP_PORT = 103, + GA_IE_RTP_UDP_PORT = 104, + GA_IE_RTCP_UDP_PORT = 105, + GA_IE_GERAN_RCV_SIGL_LIST = 106, + GA_IE_UTRAN_RCV_SIGL_LIST = 107, +}; + +/* 11.1.1 GA-RC and GA-CSR Message header IE */ +struct gan_rc_csr_hdr { + uint16_t len; + uint8_t pdisc:4, + skip_ind:4; + uint8_t msg_type; +} __attribute__((packed)); + +#endif /* PROTO_GSM_44_318_H */ diff --git a/src/shared/libosmocore/include/osmocom/gsm/sysinfo.h b/src/shared/libosmocore/include/osmocom/gsm/sysinfo.h index b808d6f9..06feb1de 100644 --- a/src/shared/libosmocore/include/osmocom/gsm/sysinfo.h +++ b/src/shared/libosmocore/include/osmocom/gsm/sysinfo.h @@ -37,7 +37,7 @@ typedef uint8_t sysinfo_buf_t[GSM_MACBLOCK_LEN]; extern const struct value_string osmo_sitype_strs[_MAX_SYSINFO_TYPE]; -uint8_t gsm_sitype2rsl(enum osmo_sysinfo_type si_type); +uint8_t osmo_sitype2rsl(enum osmo_sysinfo_type si_type); enum osmo_sysinfo_type osmo_rsl2sitype(uint8_t rsl_si); #endif /* _OSMO_GSM_SYSINFO_H */ diff --git a/src/shared/libosmocore/include/osmocom/vty/vty.h b/src/shared/libosmocore/include/osmocom/vty/vty.h index d1f6f440..ffe3c591 100644 --- a/src/shared/libosmocore/include/osmocom/vty/vty.h +++ b/src/shared/libosmocore/include/osmocom/vty/vty.h @@ -179,6 +179,9 @@ int vty_current_node(struct vty *vty); extern void *tall_vty_ctx; +extern struct cmd_element cfg_description_cmd; +extern struct cmd_element cfg_no_description_cmd; + /*! }@ */ #endif |