\doxysection{include/osmocom/core/isdnhdlc.h File Reference}
\label{isdnhdlc_8h}\index{include/osmocom/core/isdnhdlc.h@{include/osmocom/core/isdnhdlc.h}}
{\ttfamily \#include $<$stdint.\+h$>$}\newline
\doxysubsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars}
\end{DoxyCompactItemize}
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+56\+KBIT}~0x01
\item 
\#define \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+\+DCHANNEL}~0x02
\item 
\#define \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+\+BITREVERSE}~0x04
\item 
\#define \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+FRAMING\+\_\+\+ERROR}~1
\item 
\#define \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+CRC\+\_\+\+ERROR}~2
\item 
\#define \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+LENGTH\+\_\+\+ERROR}~3
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \textbf{ osmo\+\_\+isdnhdlc\+\_\+rcv\+\_\+init} (struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$hdlc, uint32\+\_\+t features)
\item 
int \textbf{ osmo\+\_\+isdnhdlc\+\_\+decode} (struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$hdlc, const uint8\+\_\+t $\ast$src, int slen, int $\ast$count, uint8\+\_\+t $\ast$dst, int dsize)
\begin{DoxyCompactList}\small\item\em decodes HDLC frames from a transparent bit stream. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+isdnhdlc\+\_\+out\+\_\+init} (struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$hdlc, uint32\+\_\+t features)
\item 
int \textbf{ osmo\+\_\+isdnhdlc\+\_\+encode} (struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$hdlc, const uint8\+\_\+t $\ast$src, uint16\+\_\+t slen, int $\ast$count, uint8\+\_\+t $\ast$dst, int dsize)
\begin{DoxyCompactList}\small\item\em encodes HDLC frames to a transparent bit stream. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Macro Definition Documentation}
\mbox{\label{isdnhdlc_8h_a24a5ef2e6d89c76e137dbadd829d37de}} 
\index{isdnhdlc.h@{isdnhdlc.h}!OSMO\_HDLC\_CRC\_ERROR@{OSMO\_HDLC\_CRC\_ERROR}}
\index{OSMO\_HDLC\_CRC\_ERROR@{OSMO\_HDLC\_CRC\_ERROR}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{OSMO\_HDLC\_CRC\_ERROR}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+HDLC\+\_\+\+CRC\+\_\+\+ERROR~2}

\mbox{\label{isdnhdlc_8h_acec3d6758ab5b2c1dd2d9d7c46c29905}} 
\index{isdnhdlc.h@{isdnhdlc.h}!OSMO\_HDLC\_F\_56KBIT@{OSMO\_HDLC\_F\_56KBIT}}
\index{OSMO\_HDLC\_F\_56KBIT@{OSMO\_HDLC\_F\_56KBIT}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{OSMO\_HDLC\_F\_56KBIT}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+56\+KBIT~0x01}

\mbox{\label{isdnhdlc_8h_af7b5ae113e9012c6c8c2279064e97801}} 
\index{isdnhdlc.h@{isdnhdlc.h}!OSMO\_HDLC\_F\_BITREVERSE@{OSMO\_HDLC\_F\_BITREVERSE}}
\index{OSMO\_HDLC\_F\_BITREVERSE@{OSMO\_HDLC\_F\_BITREVERSE}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{OSMO\_HDLC\_F\_BITREVERSE}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+\+BITREVERSE~0x04}

\mbox{\label{isdnhdlc_8h_a918fed49abc9e93630fe0153cbaffcd0}} 
\index{isdnhdlc.h@{isdnhdlc.h}!OSMO\_HDLC\_F\_DCHANNEL@{OSMO\_HDLC\_F\_DCHANNEL}}
\index{OSMO\_HDLC\_F\_DCHANNEL@{OSMO\_HDLC\_F\_DCHANNEL}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{OSMO\_HDLC\_F\_DCHANNEL}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+\+DCHANNEL~0x02}

\mbox{\label{isdnhdlc_8h_a14341be0f0258c3be70cf859d8a50cd4}} 
\index{isdnhdlc.h@{isdnhdlc.h}!OSMO\_HDLC\_FRAMING\_ERROR@{OSMO\_HDLC\_FRAMING\_ERROR}}
\index{OSMO\_HDLC\_FRAMING\_ERROR@{OSMO\_HDLC\_FRAMING\_ERROR}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{OSMO\_HDLC\_FRAMING\_ERROR}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+HDLC\+\_\+\+FRAMING\+\_\+\+ERROR~1}

\mbox{\label{isdnhdlc_8h_a5dc56dbb97b0b1a761afdbb1a28ecacc}} 
\index{isdnhdlc.h@{isdnhdlc.h}!OSMO\_HDLC\_LENGTH\_ERROR@{OSMO\_HDLC\_LENGTH\_ERROR}}
\index{OSMO\_HDLC\_LENGTH\_ERROR@{OSMO\_HDLC\_LENGTH\_ERROR}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{OSMO\_HDLC\_LENGTH\_ERROR}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+HDLC\+\_\+\+LENGTH\+\_\+\+ERROR~3}



\doxysubsection{Function Documentation}
\mbox{\label{isdnhdlc_8h_a7b51c27274ca2cccf23b4e868c7b6710}} 
\index{isdnhdlc.h@{isdnhdlc.h}!osmo\_isdnhdlc\_decode@{osmo\_isdnhdlc\_decode}}
\index{osmo\_isdnhdlc\_decode@{osmo\_isdnhdlc\_decode}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{osmo\_isdnhdlc\_decode()}
{\footnotesize\ttfamily int osmo\+\_\+isdnhdlc\+\_\+decode (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$}]{hdlc,  }\item[{const uint8\+\_\+t $\ast$}]{src,  }\item[{int}]{slen,  }\item[{int $\ast$}]{count,  }\item[{uint8\+\_\+t $\ast$}]{dst,  }\item[{int}]{dsize }\end{DoxyParamCaption})}



decodes HDLC frames from a transparent bit stream. 

The source buffer is scanned for valid HDLC frames looking for flags (01111110) to indicate the start of a frame. If the start of the frame is found, the bit stuffing is removed (0 after 5 1\textquotesingle{}s). When a new flag is found, the complete frame has been received and the CRC is checked. If a valid frame is found, the function returns the frame length excluding the CRC. If the beginning of a valid frame is found, the function returns the length. If a framing error is found (too many 1s and not a flag) the function returns -\/OSMO\+\_\+\+HDLC\+\_\+\+FRAMING\+\_\+\+ERROR. If a CRC error is found the function returns -\/OSMO\+\_\+\+HDLC\+\_\+\+CRC\+\_\+\+ERROR. If the frame length exceeds the destination buffer size, the function returns the length with the bit OSMO\+\_\+\+HDLC\+\_\+\+LENGTH\+\_\+\+ERROR set.


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em src} & source buffer \\
\hline
\mbox{\texttt{ in}}  & {\em slen} & source buffer length \\
\hline
\mbox{\texttt{ out}}  & {\em count} & number of bytes removed (decoded) from the source buffer \\
\hline
\mbox{\texttt{ out}}  & {\em dst} & destination buffer \\
\hline
\mbox{\texttt{ in}}  & {\em dsize} & destination buffer size \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of decoded bytes in the destination buffer and status flag. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::bit\+\_\+shift}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::cbin}, \textbf{ check\+\_\+frame()}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::crc}, \textbf{ crc\+\_\+ccitt\+\_\+byte}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::data\+\_\+bits}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::data\+\_\+received}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+adapt56}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+bitreverse}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::dstpos}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::ffbit\+\_\+shift}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::ffvalue}, \textbf{ handle\+\_\+abort}, \textbf{ handle\+\_\+fast\+\_\+flag}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::hdlc\+\_\+bits1}, \textbf{ HDLC\+\_\+\+FAST\+\_\+\+FLAG}, \textbf{ HDLC\+\_\+\+FAST\+\_\+\+IDLE}, \textbf{ HDLC\+\_\+\+GET\+\_\+\+DATA}, \textbf{ HDLC\+\_\+\+GET\+\_\+\+FLAG\+\_\+\+B0}, \textbf{ HDLC\+\_\+\+GETFLAG\+\_\+\+B1\+A6}, \textbf{ HDLC\+\_\+\+GETFLAG\+\_\+\+B7}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+FRAMING\+\_\+\+ERROR}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+LENGTH\+\_\+\+ERROR}, \textbf{ osmo\+\_\+revbytebits\+\_\+8()}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::shift\+\_\+reg}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::state}, and \textbf{ STOPPED}.

\mbox{\label{isdnhdlc_8h_a1b8eb0afa747804742eab4c1d59494c2}} 
\index{isdnhdlc.h@{isdnhdlc.h}!osmo\_isdnhdlc\_encode@{osmo\_isdnhdlc\_encode}}
\index{osmo\_isdnhdlc\_encode@{osmo\_isdnhdlc\_encode}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{osmo\_isdnhdlc\_encode()}
{\footnotesize\ttfamily int osmo\+\_\+isdnhdlc\+\_\+encode (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$}]{hdlc,  }\item[{const uint8\+\_\+t $\ast$}]{src,  }\item[{uint16\+\_\+t}]{slen,  }\item[{int $\ast$}]{count,  }\item[{uint8\+\_\+t $\ast$}]{dst,  }\item[{int}]{dsize }\end{DoxyParamCaption})}



encodes HDLC frames to a transparent bit stream. 

The bit stream starts with a beginning flag (01111110). After that each byte is added to the bit stream with bit stuffing added (0 after 5 1\textquotesingle{}s). When the last byte has been removed from the source buffer, the CRC (2 bytes is added) and the frame terminates with the ending flag. For the dchannel, the idle character (all 1\textquotesingle{}s) is also added at the end. If this function is called with empty source buffer (slen=0), flags or idle character will be generated.


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em src} & source buffer \\
\hline
\mbox{\texttt{ in}}  & {\em slen} & source buffer length \\
\hline
\mbox{\texttt{ out}}  & {\em count} & number of bytes removed (encoded) from source buffer \\
\hline
\mbox{\texttt{ out}}  & {\em dst} & destination buffer \\
\hline
\mbox{\texttt{ in}}  & {\em dsize} & destination buffer size \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
-\/ number of encoded bytes in the destination buffer 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::bit\+\_\+shift}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::cbin}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::crc}, \textbf{ crc\+\_\+ccitt\+\_\+byte}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::data\+\_\+bits}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::data\+\_\+received}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::dchannel}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+adapt56}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+bitreverse}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+closing}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::ffvalue}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::hdlc\+\_\+bits1}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+CLOSING\+\_\+\+FLAG}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+CRC1}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+CRC2}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+DATA}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+FAST\+\_\+\+FLAG}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+FAST\+\_\+\+IDLE}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+FIRST\+\_\+\+FLAG}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+IDLE1}, \textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+B0}, \textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+B1\+A6}, \textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+B7}, \textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+ONE}, \textbf{ len()}, \textbf{ osmo\+\_\+revbytebits\+\_\+8()}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::shift\+\_\+reg}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::state}, and \textbf{ STOPPED}.

\mbox{\label{isdnhdlc_8h_abe1a5cfbb77cc0324b1ac506cbc8967d}} 
\index{isdnhdlc.h@{isdnhdlc.h}!osmo\_isdnhdlc\_out\_init@{osmo\_isdnhdlc\_out\_init}}
\index{osmo\_isdnhdlc\_out\_init@{osmo\_isdnhdlc\_out\_init}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{osmo\_isdnhdlc\_out\_init()}
{\footnotesize\ttfamily void osmo\+\_\+isdnhdlc\+\_\+out\+\_\+init (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$}]{hdlc,  }\item[{uint32\+\_\+t}]{features }\end{DoxyParamCaption})}



References \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::cbin}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::data\+\_\+bits}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::dchannel}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+adapt56}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+bitreverse}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::ffvalue}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+FAST\+\_\+\+FLAG}, \textbf{ HDLC\+\_\+\+SEND\+\_\+\+FIRST\+\_\+\+FLAG}, \textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+B0}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+56\+KBIT}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+\+BITREVERSE}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+\+DCHANNEL}, and \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::state}.

\mbox{\label{isdnhdlc_8h_a98822a5ed1411cc5e7261f1e1e991152}} 
\index{isdnhdlc.h@{isdnhdlc.h}!osmo\_isdnhdlc\_rcv\_init@{osmo\_isdnhdlc\_rcv\_init}}
\index{osmo\_isdnhdlc\_rcv\_init@{osmo\_isdnhdlc\_rcv\_init}!isdnhdlc.h@{isdnhdlc.h}}
\doxysubsubsection{osmo\_isdnhdlc\_rcv\_init()}
{\footnotesize\ttfamily void osmo\+\_\+isdnhdlc\+\_\+rcv\+\_\+init (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$}]{hdlc,  }\item[{uint32\+\_\+t}]{features }\end{DoxyParamCaption})}



References \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+adapt56}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::do\+\_\+bitreverse}, \textbf{ HDLC\+\_\+\+GET\+\_\+\+DATA}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+56\+KBIT}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+F\+\_\+\+BITREVERSE}, and \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::state}.

