libosmoisdn 1.9.0.197-fb8cd
Osmocom ISDN library
lapd_core.c File Reference

LAPD core implementation. More...

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/talloc.h>
#include <osmocom/isdn/lapd_core.h>
#include <osmocom/gsm/rsl.h>

Data Structures

struct  l2downstate
 

Macros

#define LAPD_U_SABM   0x7
 
#define LAPD_U_SABME   0xf
 
#define LAPD_U_DM   0x3
 
#define LAPD_U_UI   0x0
 
#define LAPD_U_DISC   0x8
 
#define LAPD_U_UA   0xC
 
#define LAPD_U_FRMR   0x11
 
#define LAPD_S_RR   0x0
 
#define LAPD_S_RNR   0x1
 
#define LAPD_S_REJ   0x2
 
#define CR_USER2NET_CMD   0
 
#define CR_USER2NET_RESP   1
 
#define CR_NET2USER_CMD   1
 
#define CR_NET2USER_RESP   0
 
#define LAPD_HEADROOM   56
 
#define LAPD_TAILROOM   16
 
#define SBIT(a)   (1 << a)
 
#define ALL_STATES   0xffffffff
 
#define L2DOWNSLLEN    (sizeof(l2downstatelist) / sizeof(struct l2downstate))
 

Functions

static void lapd_t200_cb (void *data)
 
static void lapd_t203_cb (void *data)
 
static int lapd_send_i (struct lapd_datalink *dl, int line, bool rts)
 
static int lapd_est_req (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
struct msgblapd_msgb_alloc (int length, const char *name)
 
static uint8_t do_mod (uint8_t x, uint8_t m)
 
static uint8_t inc_mod (uint8_t x, uint8_t m)
 
static uint8_t add_mod (uint8_t x, uint8_t y, uint8_t m)
 
static uint8_t sub_mod (uint8_t x, uint8_t y, uint8_t m)
 
static void lapd_dl_flush_send (struct lapd_datalink *dl)
 
static void lapd_dl_flush_hist (struct lapd_datalink *dl)
 
static void lapd_dl_flush_tx_queue (struct lapd_datalink *dl)
 
static void lapd_dl_flush_tx (struct lapd_datalink *dl)
 
static const char * lapd_state_name (enum lapd_state state)
 
static void lapd_start_t200 (struct lapd_datalink *dl)
 
int lapd_t200_timeout (struct lapd_datalink *dl)
 Handle timeout condition of T200 in RTS mode. More...
 
static void lapd_start_t203 (struct lapd_datalink *dl)
 
static void lapd_stop_t200 (struct lapd_datalink *dl)
 
static bool lapd_is_t200_started (struct lapd_datalink *dl)
 
static void lapd_stop_t203 (struct lapd_datalink *dl)
 
static void lapd_dl_newstate (struct lapd_datalink *dl, uint32_t state)
 
void lapd_dl_init2 (struct lapd_datalink *dl, uint8_t k, uint8_t v_range, int maxf, const char *name)
 Initialize LAPD datalink instance and allocate history. More...
 
void lapd_dl_init (struct lapd_datalink *dl, uint8_t k, uint8_t v_range, int maxf)
 Initialize LAPD datalink instance and allocate history. More...
 
void lapd_dl_set_name (struct lapd_datalink *dl, const char *name)
 
void lapd_dl_reset (struct lapd_datalink *dl)
 
int lapd_dl_set_flags (struct lapd_datalink *dl, unsigned int flags)
 Set lapd_flags to change behaviour. More...
 
void lapd_dl_exit (struct lapd_datalink *dl)
 
int lapd_set_mode (struct lapd_datalink *dl, enum lapd_mode mode)
 Set the lapdm_mode of a LAPDm entity. More...
 
static int send_dl_l3 (uint8_t prim, uint8_t op, struct lapd_msg_ctx *lctx, struct msgb *msg)
 
static int send_dl_simple (uint8_t prim, uint8_t op, struct lapd_msg_ctx *lctx)
 
static int mdl_error (uint8_t cause, struct lapd_msg_ctx *lctx)
 
static int lapd_send_ua (struct lapd_msg_ctx *lctx, uint8_t len, uint8_t *data)
 
static int lapd_send_dm (struct lapd_msg_ctx *lctx)
 
static int lapd_send_rr (struct lapd_msg_ctx *lctx, uint8_t f_bit, uint8_t cmd)
 
static int lapd_send_rnr (struct lapd_msg_ctx *lctx, uint8_t f_bit, uint8_t cmd)
 
static int lapd_send_rej (struct lapd_msg_ctx *lctx, uint8_t f_bit)
 
static int lapd_send_resend (struct lapd_datalink *dl)
 
static int lapd_reestablish (struct lapd_datalink *dl)
 
static int lapd_acknowledge (struct lapd_msg_ctx *lctx)
 
static int lapd_rx_u_sabm (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_u_dm (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_u_ui (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_u_disc (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_u_ua (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_u_frmr (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_u (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_s (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
static int lapd_rx_i (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
int lapd_ph_data_ind (struct msgb *msg, struct lapd_msg_ctx *lctx)
 
int lapd_ph_rts_ind (struct lapd_msg_ctx *lctx)
 Enqueue next LAPD frame and run pending T200. More...
 
static int lapd_udata_req (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
static void msg_to_tx_hist (struct lapd_history *tx_hist, const struct msgb *msg, int length, int more)
 
static void msg_to_tx_hist0 (struct lapd_datalink *dl, const struct msgb *msg)
 
static int lapd_data_req (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
static int lapd_susp_req (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
static int lapd_res_req (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
static int lapd_rel_req (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
static int lapd_rel_req_idle (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 
int lapd_recv_dlsap (struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx)
 

Variables

const struct value_string lapd_state_names []
 
void * tall_lapd_ctx = NULL
 
static const struct l2downstate l2downstatelist []
 

Detailed Description

LAPD core implementation.