\doxysection{src/isdn/lapd\+\_\+core.c File Reference}
\label{lapd__core_8c}\index{src/isdn/lapd\_core.c@{src/isdn/lapd\_core.c}}


LAPD core implementation.  


{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$stdbool.\+h$>$}\newline
{\ttfamily \#include $<$stdint.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$errno.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/logging.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/timer.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/msgb.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/utils.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/talloc.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/isdn/lapd\+\_\+core.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/gsm/rsl.\+h$>$}\newline
\doxysubsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \textbf{ l2downstate}
\end{DoxyCompactItemize}
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ LAPD\+\_\+\+U\+\_\+\+SABM}~0x7
\item 
\#define \textbf{ LAPD\+\_\+\+U\+\_\+\+SABME}~0xf
\item 
\#define \textbf{ LAPD\+\_\+\+U\+\_\+\+DM}~0x3
\item 
\#define \textbf{ LAPD\+\_\+\+U\+\_\+\+UI}~0x0
\item 
\#define \textbf{ LAPD\+\_\+\+U\+\_\+\+DISC}~0x8
\item 
\#define \textbf{ LAPD\+\_\+\+U\+\_\+\+UA}~0xC
\item 
\#define \textbf{ LAPD\+\_\+\+U\+\_\+\+FRMR}~0x11
\item 
\#define \textbf{ LAPD\+\_\+\+S\+\_\+\+RR}~0x0
\item 
\#define \textbf{ LAPD\+\_\+\+S\+\_\+\+RNR}~0x1
\item 
\#define \textbf{ LAPD\+\_\+\+S\+\_\+\+REJ}~0x2
\item 
\#define \textbf{ CR\+\_\+\+USER2\+NET\+\_\+\+CMD}~0
\item 
\#define \textbf{ CR\+\_\+\+USER2\+NET\+\_\+\+RESP}~1
\item 
\#define \textbf{ CR\+\_\+\+NET2\+USER\+\_\+\+CMD}~1
\item 
\#define \textbf{ CR\+\_\+\+NET2\+USER\+\_\+\+RESP}~0
\item 
\#define \textbf{ LAPD\+\_\+\+HEADROOM}~56
\item 
\#define \textbf{ LAPD\+\_\+\+TAILROOM}~16
\item 
\#define \textbf{ SBIT}(a)~(1 $<$$<$ a)
\item 
\#define \textbf{ ALL\+\_\+\+STATES}~0xffffffff
\item 
\#define \textbf{ L2\+DOWNSLLEN}~ (sizeof(\textbf{ l2downstatelist}) / sizeof(struct \textbf{ l2downstate}))
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static void \textbf{ lapd\+\_\+t200\+\_\+cb} (void $\ast$\textbf{ data})
\item 
static void \textbf{ lapd\+\_\+t203\+\_\+cb} (void $\ast$\textbf{ data})
\item 
static int \textbf{ lapd\+\_\+send\+\_\+i} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, int line, bool rts)
\item 
static int \textbf{ lapd\+\_\+est\+\_\+req} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
struct \textbf{ msgb} $\ast$ \textbf{ lapd\+\_\+msgb\+\_\+alloc} (int length, const char $\ast$\textbf{ name})
\item 
static uint8\+\_\+t \textbf{ do\+\_\+mod} (uint8\+\_\+t \textbf{ x}, uint8\+\_\+t m)
\item 
static uint8\+\_\+t \textbf{ inc\+\_\+mod} (uint8\+\_\+t \textbf{ x}, uint8\+\_\+t m)
\item 
static uint8\+\_\+t \textbf{ add\+\_\+mod} (uint8\+\_\+t \textbf{ x}, uint8\+\_\+t y, uint8\+\_\+t m)
\item 
static uint8\+\_\+t \textbf{ sub\+\_\+mod} (uint8\+\_\+t \textbf{ x}, uint8\+\_\+t y, uint8\+\_\+t m)
\item 
static void \textbf{ lapd\+\_\+dl\+\_\+flush\+\_\+send} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static void \textbf{ lapd\+\_\+dl\+\_\+flush\+\_\+hist} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static void \textbf{ lapd\+\_\+dl\+\_\+flush\+\_\+tx\+\_\+queue} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static void \textbf{ lapd\+\_\+dl\+\_\+flush\+\_\+tx} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static const char $\ast$ \textbf{ lapd\+\_\+state\+\_\+name} (enum \textbf{ lapd\+\_\+state} state)
\item 
static void \textbf{ lapd\+\_\+start\+\_\+t200} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
int \textbf{ lapd\+\_\+t200\+\_\+timeout} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\begin{DoxyCompactList}\small\item\em Handle timeout condition of T200 in RTS mode. \end{DoxyCompactList}\item 
static void \textbf{ lapd\+\_\+start\+\_\+t203} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static void \textbf{ lapd\+\_\+stop\+\_\+t200} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static bool \textbf{ lapd\+\_\+is\+\_\+t200\+\_\+started} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static void \textbf{ lapd\+\_\+stop\+\_\+t203} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static void \textbf{ lapd\+\_\+dl\+\_\+newstate} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, uint32\+\_\+t state)
\item 
void \textbf{ lapd\+\_\+dl\+\_\+init2} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, uint8\+\_\+t k, uint8\+\_\+t v\+\_\+range, int maxf, const char $\ast$\textbf{ name})
\begin{DoxyCompactList}\small\item\em Initialize LAPD datalink instance and allocate history. \end{DoxyCompactList}\item 
void \textbf{ lapd\+\_\+dl\+\_\+init} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, uint8\+\_\+t k, uint8\+\_\+t v\+\_\+range, int maxf)
\begin{DoxyCompactList}\small\item\em Initialize LAPD datalink instance and allocate history. \end{DoxyCompactList}\item 
void \textbf{ lapd\+\_\+dl\+\_\+set\+\_\+name} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, const char $\ast$\textbf{ name})
\item 
void \textbf{ lapd\+\_\+dl\+\_\+reset} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
int \textbf{ lapd\+\_\+dl\+\_\+set\+\_\+flags} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, unsigned int \textbf{ flags})
\begin{DoxyCompactList}\small\item\em Set lapd\+\_\+flags to change behaviour. \end{DoxyCompactList}\item 
void \textbf{ lapd\+\_\+dl\+\_\+exit} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
int \textbf{ lapd\+\_\+set\+\_\+mode} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, enum \textbf{ lapd\+\_\+mode} mode)
\begin{DoxyCompactList}\small\item\em Set the lapdm\+\_\+mode of a LAPDm entity. \end{DoxyCompactList}\item 
static int \textbf{ send\+\_\+dl\+\_\+l3} (uint8\+\_\+t prim, uint8\+\_\+t op, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx, struct \textbf{ msgb} $\ast$msg)
\item 
static int \textbf{ send\+\_\+dl\+\_\+simple} (uint8\+\_\+t prim, uint8\+\_\+t op, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ mdl\+\_\+error} (uint8\+\_\+t cause, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+send\+\_\+ua} (struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx, uint8\+\_\+t \textbf{ len}, uint8\+\_\+t $\ast$\textbf{ data})
\item 
static int \textbf{ lapd\+\_\+send\+\_\+dm} (struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+send\+\_\+rr} (struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx, uint8\+\_\+t f\+\_\+bit, uint8\+\_\+t cmd)
\item 
static int \textbf{ lapd\+\_\+send\+\_\+rnr} (struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx, uint8\+\_\+t f\+\_\+bit, uint8\+\_\+t cmd)
\item 
static int \textbf{ lapd\+\_\+send\+\_\+rej} (struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx, uint8\+\_\+t f\+\_\+bit)
\item 
static int \textbf{ lapd\+\_\+send\+\_\+resend} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static int \textbf{ lapd\+\_\+reestablish} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl)
\item 
static int \textbf{ lapd\+\_\+acknowledge} (struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+u\+\_\+sabm} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+u\+\_\+dm} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+u\+\_\+ui} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+u\+\_\+disc} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+u\+\_\+ua} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+u\+\_\+frmr} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+u} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+s} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rx\+\_\+i} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
int \textbf{ lapd\+\_\+ph\+\_\+data\+\_\+ind} (struct \textbf{ msgb} $\ast$msg, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
int \textbf{ lapd\+\_\+ph\+\_\+rts\+\_\+ind} (struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\begin{DoxyCompactList}\small\item\em Enqueue next LAPD frame and run pending T200. \end{DoxyCompactList}\item 
static int \textbf{ lapd\+\_\+udata\+\_\+req} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static void \textbf{ msg\+\_\+to\+\_\+tx\+\_\+hist} (struct \textbf{ lapd\+\_\+history} $\ast$tx\+\_\+hist, const struct \textbf{ msgb} $\ast$msg, int length, int more)
\item 
static void \textbf{ msg\+\_\+to\+\_\+tx\+\_\+hist0} (struct \textbf{ lapd\+\_\+datalink} $\ast$dl, const struct \textbf{ msgb} $\ast$msg)
\item 
static int \textbf{ lapd\+\_\+data\+\_\+req} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+susp\+\_\+req} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+res\+\_\+req} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rel\+\_\+req} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
static int \textbf{ lapd\+\_\+rel\+\_\+req\+\_\+idle} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\item 
int \textbf{ lapd\+\_\+recv\+\_\+dlsap} (struct \textbf{ osmo\+\_\+dlsap\+\_\+prim} $\ast$dp, struct \textbf{ lapd\+\_\+msg\+\_\+ctx} $\ast$lctx)
\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
const struct \textbf{ value\+\_\+string} \textbf{ lapd\+\_\+state\+\_\+names} [$\,$]
\item 
void $\ast$ \textbf{ tall\+\_\+lapd\+\_\+ctx} = NULL
\item 
static const struct \textbf{ l2downstate} \textbf{ l2downstatelist} [$\,$]
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
LAPD core implementation. 

