aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom
diff options
context:
space:
mode:
Diffstat (limited to 'include/osmocom')
-rw-r--r--include/osmocom/core/Makefile.am2
-rw-r--r--include/osmocom/core/application.h2
-rw-r--r--include/osmocom/core/logging.h18
-rw-r--r--include/osmocom/core/msgb.h2
-rw-r--r--include/osmocom/core/prim.h38
-rw-r--r--include/osmocom/core/process.h8
-rw-r--r--include/osmocom/core/socket.h11
-rw-r--r--include/osmocom/core/utils.h1
-rw-r--r--include/osmocom/gsm/Makefile.am2
-rw-r--r--include/osmocom/gsm/gsm0502.h38
-rw-r--r--include/osmocom/gsm/gsm48.h2
-rw-r--r--include/osmocom/gsm/gsm_utils.h2
-rw-r--r--include/osmocom/gsm/lapdm.h186
-rw-r--r--include/osmocom/gsm/prim.h13
-rw-r--r--include/osmocom/gsm/protocol/gsm_08_58.h2
-rw-r--r--include/osmocom/gsm/rsl.h2
-rw-r--r--include/osmocom/gsm/sysinfo.h2
17 files changed, 313 insertions, 18 deletions
diff --git a/include/osmocom/core/Makefile.am b/include/osmocom/core/Makefile.am
index 3c30362c..1ef37693 100644
--- a/include/osmocom/core/Makefile.am
+++ b/include/osmocom/core/Makefile.am
@@ -1,6 +1,6 @@
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 \
+ gsmtap.h write_queue.h prim.h \
logging.h rate_ctr.h gsmtap_util.h \
plugin.h crc16.h panic.h process.h msgfile.h \
backtrace.h conv.h application.h
diff --git a/include/osmocom/core/application.h b/include/osmocom/core/application.h
index c1642ec4..5d098961 100644
--- a/include/osmocom/core/application.h
+++ b/include/osmocom/core/application.h
@@ -13,4 +13,6 @@ extern struct log_target *osmo_stderr_target;
void osmo_init_ignore_signals(void);
int osmo_init_logging(const struct log_info *);
+int osmo_daemonize(void);
+
#endif
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index db029402..4276b3af 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -5,7 +5,6 @@
#include <stdint.h>
#include <osmocom/core/linuxlist.h>
-#define LOG_MAX_CATEGORY 32
#define LOG_MAX_CTX 8
#define LOG_MAX_FILTERS 8
@@ -20,7 +19,7 @@
#endif
-void logp(unsigned int subsys, char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
+void logp(int subsys, char *file, int line, int cont, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
/* new logging interface */
#define LOGP(ss, level, fmt, args...) \
@@ -37,6 +36,11 @@ void logp(unsigned int subsys, char *file, int line, int cont, const char *forma
#define LOG_FILTER_ALL 0x0001
+/* logging levels defined by the library itself */
+#define DLGLOBAL -1
+#define DLLAPDM -2
+#define OSMO_NUM_DLIB 2
+
struct log_category {
uint8_t loglevel;
uint8_t enabled;
@@ -65,8 +69,9 @@ struct log_info {
log_filter *filter_fn;
/* per-category information */
- const struct log_info_cat *cat;
+ struct log_info_cat *cat;
unsigned int num_cat;
+ unsigned int num_cat_user;
};
enum log_target_type {
@@ -82,7 +87,8 @@ struct log_target {
int filter_map;
void *filter_data[LOG_MAX_FILTERS+1];
- struct log_category categories[LOG_MAX_CATEGORY+1];
+ struct log_category *categories;
+
uint8_t loglevel;
int use_color:1;
int print_timestamp:1;
@@ -110,10 +116,10 @@ struct log_target {
};
/* use the above macros */
-void logp2(unsigned int subsys, unsigned int level, char *file,
+void logp2(int subsys, unsigned int level, char *file,
int line, int cont, const char *format, ...)
__attribute__ ((format (printf, 6, 7)));
-void log_init(const struct log_info *cat);
+int log_init(const struct log_info *inf, void *talloc_ctx);
/* context management */
void log_reset_context(void);
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h
index 8665c2bf..58976f7f 100644
--- a/include/osmocom/core/msgb.h
+++ b/include/osmocom/core/msgb.h
@@ -193,5 +193,7 @@ static inline struct msgb *msgb_alloc_headroom(int size, int headroom,
uint8_t *msgb_data(const struct msgb *msg);
uint16_t msgb_length(const struct msgb *msg);
+/* set the talloc context for msgb_alloc[_headroom] */
+void msgb_set_talloc_ctx(void *ctx);
#endif /* _MSGB_H */
diff --git a/include/osmocom/core/prim.h b/include/osmocom/core/prim.h
new file mode 100644
index 00000000..e892c62c
--- /dev/null
+++ b/include/osmocom/core/prim.h
@@ -0,0 +1,38 @@
+#ifndef OSMO_PRIMITIVE_H
+#define OSMO_PRIMITIVE_H
+
+#include <stdint.h>
+#include <osmocom/core/msgb.h>
+
+enum osmo_prim_operation {
+ PRIM_OP_REQUEST,
+ PRIM_OP_RESPONSE,
+ PRIM_OP_INDICATION,
+ PRIM_OP_CONFIRM,
+};
+
+#define _SAP_GSM_SHIFT 24
+
+#define _SAP_GSM_BASE (0x01 << _SAP_GSM_SHIFT)
+#define _SAP_TETRA_BASE (0x02 << _SAP_GSM_SHIFT)
+
+struct osmo_prim_hdr {
+ unsigned int sap;
+ unsigned int primitive;
+ enum osmo_prim_operation operation;
+ struct msgb *msg; /* message containing associated data */
+};
+
+static inline void
+osmo_prim_init(struct osmo_prim_hdr *oph, unsigned int sap,
+ unsigned int primitive, enum osmo_prim_operation operation,
+ struct msgb *msg)
+{
+ oph->sap = sap;
+ oph->primitive = primitive;
+ oph->operation = operation;
+ oph->msg = msg;
+}
+
+typedef int (*osmo_prim_cb)(struct osmo_prim_hdr *oph, void *ctx);
+#endif
diff --git a/include/osmocom/core/process.h b/include/osmocom/core/process.h
index 2d663828..1dde0219 100644
--- a/include/osmocom/core/process.h
+++ b/include/osmocom/core/process.h
@@ -1,6 +1,2 @@
-#ifndef _OSMO_PROCESS_H
-#define _OSMO_PROCESS_H
-
-int osmo_daemonize(void);
-
-#endif
+#warning "Update from osmocom/core/process.h to osmocom/core/application.h"
+#include <osmocom/core/application.h>
diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index b2601c76..612b12c8 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -5,14 +5,19 @@
struct sockaddr;
+/* flags for osmo_sock_init. */
+#define OSMO_SOCK_F_CONNECT (1 << 0)
+#define OSMO_SOCK_F_BIND (1 << 1)
+#define OSMO_SOCK_F_NONBLOCK (1 << 2)
+
int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
- const char *host, uint16_t port, int connect0_bind1);
+ const char *host, uint16_t port, unsigned int flags);
int osmo_sock_init_ofd(struct osmo_fd *ofd, int family, int type, int proto,
- const char *host, uint16_t port, int connect0_bind1);
+ const char *host, uint16_t port, unsigned int flags);
int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type,
- uint8_t proto, int connect0_bind1);
+ uint8_t proto, unsigned int flags);
/* determine if the given address is a local address */
int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen);
diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h
index 0f1ea3bb..01b0ab99 100644
--- a/include/osmocom/core/utils.h
+++ b/include/osmocom/core/utils.h
@@ -2,6 +2,7 @@
#define OSMOCORE_UTIL_H
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define OSMO_MAX(a, b) (a) >= (b) ? (a) : (b)
#include <stdint.h>
diff --git a/include/osmocom/gsm/Makefile.am b/include/osmocom/gsm/Makefile.am
index 547933ec..90f19bc5 100644
--- a/include/osmocom/gsm/Makefile.am
+++ b/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
+ sysinfo.h prim.h gsm0502.h lapdm.h
SUBDIRS = protocol
diff --git a/include/osmocom/gsm/gsm0502.h b/include/osmocom/gsm/gsm0502.h
new file mode 100644
index 00000000..46b629e4
--- /dev/null
+++ b/include/osmocom/gsm/gsm0502.h
@@ -0,0 +1,38 @@
+#ifndef OSMOCOM_GSM_0502_H
+#define OSMOCOM_GSM_0502_H
+
+#include <stdint.h>
+
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+#include <osmocom/gsm/protocol/gsm_08_58.h>
+
+/* Table 5 Clause 7 TS 05.02 */
+static inline unsigned int
+gsm0502_get_n_pag_blocks(struct gsm48_control_channel_descr *chan_desc)
+{
+ if (chan_desc->ccch_conf == RSL_BCCH_CCCH_CONF_1_C)
+ return 3 - chan_desc->bs_ag_blks_res;
+ else
+ return 9 - chan_desc->bs_ag_blks_res;
+}
+
+/* Chapter 6.5.2 of TS 05.02 */
+static inline unsigned int
+gsm0502_get_ccch_group(uint64_t imsi, unsigned int bs_cc_chans,
+ unsigned int n_pag_blocks)
+{
+ return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) / n_pag_blocks;
+}
+
+/* Chapter 6.5.2 of TS 05.02 */
+static inline unsigned int
+gsm0502_get_paging_group(uint64_t imsi, unsigned int bs_cc_chans,
+ int n_pag_blocks)
+{
+ return (imsi % 1000) % (bs_cc_chans * n_pag_blocks) % n_pag_blocks;
+}
+
+unsigned int
+gsm0502_calc_paging_group(struct gsm48_control_channel_descr *chan_desc, uint64_t imsi);
+
+#endif
diff --git a/include/osmocom/gsm/gsm48.h b/include/osmocom/gsm/gsm48.h
index 1e9403bc..16a625aa 100644
--- a/include/osmocom/gsm/gsm48.h
+++ b/include/osmocom/gsm/gsm48.h
@@ -33,4 +33,6 @@ int gsm48_mi_to_string(char *string, const int str_len,
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid);
+int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc);
+
#endif
diff --git a/include/osmocom/gsm/gsm_utils.h b/include/osmocom/gsm/gsm_utils.h
index a0ef3c4f..405dfe32 100644
--- a/include/osmocom/gsm/gsm_utils.h
+++ b/include/osmocom/gsm/gsm_utils.h
@@ -59,6 +59,8 @@ enum gsm_band gsm_band_parse(const char *mhz);
int gsm_7bit_decode(char *decoded, const uint8_t *user_data, uint8_t length);
int gsm_7bit_encode(uint8_t *result, const char *data);
+unsigned int ms_class_gmsk_dbm(enum gsm_band band, int class);
+
int ms_pwr_ctl_lvl(enum gsm_band band, unsigned int dbm);
int ms_pwr_dbm(enum gsm_band band, uint8_t lvl);
diff --git a/include/osmocom/gsm/lapdm.h b/include/osmocom/gsm/lapdm.h
new file mode 100644
index 00000000..2e78aeee
--- /dev/null
+++ b/include/osmocom/gsm/lapdm.h
@@ -0,0 +1,186 @@
+#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>
+
+/* primitive related sutff */
+
+enum osmo_ph_prim {
+ PRIM_PH_DATA, /* PH-DATA */
+ PRIM_PH_RACH, /* PH-RANDOM_ACCESS */
+ PRIM_PH_CONN, /* PH-CONNECT */
+ PRIM_PH_EMPTY_FRAME, /* PH-EMPTY_FRAME */
+ PRIM_PH_RTS, /* PH-RTS */
+};
+
+/* for PH-RANDOM_ACCESS.req */
+struct ph_rach_req_param {
+ uint8_t ra;
+ uint8_t ta;
+ uint8_t tx_power;
+ uint8_t is_combined_ccch;
+ uint16_t offset;
+};
+
+/* for PH-RANDOM_ACCESS.ind */
+struct ph_rach_ind_param {
+ uint8_t ra;
+ uint8_t acc_delay;
+ uint32_t fn;
+};
+
+/* for PH-[UNIT]DATA.{req,ind} */
+struct ph_data_param {
+ uint8_t link_id;
+ uint8_t chan_nr;
+};
+
+struct ph_conn_ind_param {
+ uint32_t fn;
+};
+
+struct osmo_phsap_prim {
+ struct osmo_prim_hdr oph;
+ union {
+ struct ph_data_param data;
+ struct ph_rach_req_param rach_req;
+ struct ph_rach_ind_param rach_ind;
+ struct ph_conn_ind_param conn_ind;
+ } u;
+};
+
+enum lapdm_mode {
+ LAPDM_MODE_MS,
+ LAPDM_MODE_BTS,
+};
+
+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;
+
+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;
+};
+
+/* TS 04.06 / Section 3.5.2 */
+struct lapdm_datalink {
+ uint8_t V_send; /* seq nr of next I frame to be transmitted */
+ uint8_t V_ack; /* last frame ACKed by peer */
+ uint8_t N_send; /* ? set to V_send at Tx time*/
+ uint8_t V_recv; /* seq nr of next I frame expected to be received */
+ uint8_t N_recv; /* expected send seq nr of the next received I frame */
+ uint32_t state;
+ int seq_err_cond; /* condition of sequence error */
+ uint8_t own_busy, peer_busy;
+ struct osmo_timer_list t200;
+ uint8_t retrans_ctr;
+ struct llist_head send_queue; /* frames from L3 */
+ struct msgb *send_buffer; /* current frame transmitting */
+ int send_out; /* how much was sent from send_buffer */
+ uint8_t tx_hist[8][200]; /* tx history buffer */
+ int tx_length[8]; /* length in history buffer */
+ struct llist_head tx_queue; /* frames to L1 */
+ struct lapdm_msg_ctx mctx; /* context of established connection */
+ struct msgb *rcv_buffer; /* buffer to assemble the received message */
+
+ struct lapdm_entity *entity;
+};
+
+enum lapdm_dl_sapi {
+ DL_SAPI0 = 0,
+ DL_SAPI3 = 1,
+ _NR_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
+
+/* register message handler for messages that are sent from L2->L3 */
+struct lapdm_entity {
+ struct lapdm_datalink datalink[_NR_DL_SAPI];
+ int last_tx_dequeue; /* last entity that was dequeued */
+ int tx_pending; /* currently a pending frame not confirmed by L1 */
+ enum lapdm_mode mode; /* are we in BTS mode or MS mode */
+ unsigned int flags;
+
+ struct {
+ /* filled-in once we set the lapdm_mode above */
+ struct lapdm_cr_ent loc2rem;
+ struct lapdm_cr_ent rem2loc;
+ } cr;
+
+ void *l1_ctx; /* context for layer1 instance */
+ void *l3_ctx; /* context for layer3 instance */
+
+ osmo_prim_cb l1_prim_cb;
+ lapdm_cb_t l3_cb; /* callback for sending stuff to L3 */
+
+ struct lapdm_channel *lapdm_ch;
+};
+
+/* the two lapdm_entities that form a GSM logical channel (ACCH + DCCH) */
+struct lapdm_channel {
+ struct llist_head list;
+ char *name;
+ struct lapdm_entity lapdm_acch;
+ struct lapdm_entity lapdm_dcch;
+};
+
+const char *get_rsl_name(int value);
+extern const char *lapdm_state_names[];
+
+/* initialize a LAPDm entity */
+void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode);
+void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode);
+
+/* deinitialize a LAPDm entity */
+void lapdm_entity_exit(struct lapdm_entity *le);
+void lapdm_channel_exit(struct lapdm_channel *lc);
+
+/* input into layer2 (from layer 1) */
+int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le);
+
+/* input into layer2 (from layer 3) */
+int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc);
+
+void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx);
+void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx);
+
+int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode);
+int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode);
+
+void lapdm_entity_reset(struct lapdm_entity *le);
+void lapdm_channel_reset(struct lapdm_channel *lc);
+
+void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags);
+void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags);
+
+int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp);
+
+#endif /* _OSMOCOM_LAPDM_H */
diff --git a/include/osmocom/gsm/prim.h b/include/osmocom/gsm/prim.h
new file mode 100644
index 00000000..95cbb120
--- /dev/null
+++ b/include/osmocom/gsm/prim.h
@@ -0,0 +1,13 @@
+#ifndef OSMO_GSM_PRIM_H
+#define OSMO_GSM_PRIM_H
+
+#include <osmocom/core/prim.h>
+
+/* enumeration of GSM related SAPs */
+enum osmo_gsm_sap {
+ SAP_GSM_PH = _SAP_GSM_BASE,
+ SAP_GSM_DL,
+ SAP_GSM_MDL,
+};
+
+#endif
diff --git a/include/osmocom/gsm/protocol/gsm_08_58.h b/include/osmocom/gsm/protocol/gsm_08_58.h
index 74a4083b..9b641b34 100644
--- a/include/osmocom/gsm/protocol/gsm_08_58.h
+++ b/include/osmocom/gsm/protocol/gsm_08_58.h
@@ -426,7 +426,7 @@ struct rsl_ie_chan_ident {
#define RSL_SYSTEM_INFO_5bis 0x0d
#define RSL_SYSTEM_INFO_5ter 0x0e
#define RSL_SYSTEM_INFO_10 0x0f
-#define REL_EXT_MEAS_ORDER 0x47
+#define RSL_EXT_MEAS_ORDER 0x47
#define RSL_MEAS_INFO 0x48
#define RSL_SYSTEM_INFO_13 0x28
#define RSL_SYSTEM_INFO_2quater 0x29
diff --git a/include/osmocom/gsm/rsl.h b/include/osmocom/gsm/rsl.h
index 7e46330f..44ded1b1 100644
--- a/include/osmocom/gsm/rsl.h
+++ b/include/osmocom/gsm/rsl.h
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
#include <osmocom/gsm/protocol/gsm_08_58.h>
void rsl_init_rll_hdr(struct abis_rsl_rll_hdr *dh, uint8_t msg_type);
@@ -23,6 +24,7 @@ const char *rsl_chan_nr_str(uint8_t chan_nr);
const char *rsl_err_name(uint8_t err);
const char *rsl_rlm_cause_name(uint8_t err);
+const char *rsl_msg_name(uint8_t err);
/* Section 3.3.2.3 TS 05.02. I think this looks like a table */
int rsl_ccch_conf_to_bs_cc_chans(int ccch_conf);
diff --git a/include/osmocom/gsm/sysinfo.h b/include/osmocom/gsm/sysinfo.h
index 6c81134e..b808d6f9 100644
--- a/include/osmocom/gsm/sysinfo.h
+++ b/include/osmocom/gsm/sysinfo.h
@@ -27,6 +27,8 @@ enum osmo_sysinfo_type {
SYSINFO_TYPE_2quater,
SYSINFO_TYPE_5bis,
SYSINFO_TYPE_5ter,
+ SYSINFO_TYPE_EMO,
+ SYSINFO_TYPE_MEAS_INFO,
/* FIXME all the various bis and ter */
_MAX_SYSINFO_TYPE
};