\doxysection{src/core/isdnhdlc.c File Reference}
\label{isdnhdlc_8c}\index{src/core/isdnhdlc.c@{src/core/isdnhdlc.c}}
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/crc16.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/bits.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/isdnhdlc.\+h$>$}\newline
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ crc\+\_\+ccitt\+\_\+byte}~\textbf{ osmo\+\_\+crc16\+\_\+ccitt\+\_\+byte}
\item 
\#define \textbf{ handle\+\_\+fast\+\_\+flag}(\textbf{ h})
\item 
\#define \textbf{ handle\+\_\+abort}(\textbf{ h})
\end{DoxyCompactItemize}
\doxysubsection*{Enumerations}
\begin{DoxyCompactItemize}
\item 
enum \{ \newline
\textbf{ HDLC\+\_\+\+FAST\+\_\+\+IDLE}
, \newline
\textbf{ HDLC\+\_\+\+GET\+\_\+\+FLAG\+\_\+\+B0}
, \newline
\textbf{ HDLC\+\_\+\+GETFLAG\+\_\+\+B1\+A6}
, \newline
\textbf{ HDLC\+\_\+\+GETFLAG\+\_\+\+B7}
, \newline
\textbf{ HDLC\+\_\+\+GET\+\_\+\+DATA}
, \newline
\textbf{ HDLC\+\_\+\+FAST\+\_\+\+FLAG}
 \}
\item 
enum \{ \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+DATA}
, \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+CRC1}
, \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+FAST\+\_\+\+FLAG}
, \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+FIRST\+\_\+\+FLAG}
, \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+CRC2}
, \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+CLOSING\+\_\+\+FLAG}
, \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+IDLE1}
, \newline
\textbf{ HDLC\+\_\+\+SEND\+\_\+\+FAST\+\_\+\+IDLE}
, \newline
\textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+B0}
, \newline
\textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+B1\+A6}
, \newline
\textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+B7}
, \newline
\textbf{ STOPPED}
, \newline
\textbf{ HDLC\+\_\+\+SENDFLAG\+\_\+\+ONE}
 \}
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \textbf{ osmo\+\_\+isdnhdlc\+\_\+rcv\+\_\+init} (struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$hdlc, uint32\+\_\+t features)
\item 
void \textbf{ osmo\+\_\+isdnhdlc\+\_\+out\+\_\+init} (struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$hdlc, uint32\+\_\+t features)
\item 
static int \textbf{ check\+\_\+frame} (struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$hdlc)
\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 
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_8c_abff2b9b7c268ac7dbf2b4e665baee472}} 
\index{isdnhdlc.c@{isdnhdlc.c}!crc\_ccitt\_byte@{crc\_ccitt\_byte}}
\index{crc\_ccitt\_byte@{crc\_ccitt\_byte}!isdnhdlc.c@{isdnhdlc.c}}
\doxysubsubsection{crc\_ccitt\_byte}
{\footnotesize\ttfamily \#define crc\+\_\+ccitt\+\_\+byte~\textbf{ osmo\+\_\+crc16\+\_\+ccitt\+\_\+byte}}

\mbox{\label{isdnhdlc_8c_ac1ef7d0a89ea93ae75db3497653c59b3}} 
\index{isdnhdlc.c@{isdnhdlc.c}!handle\_abort@{handle\_abort}}
\index{handle\_abort@{handle\_abort}!isdnhdlc.c@{isdnhdlc.c}}
\doxysubsubsection{handle\_abort}
{\footnotesize\ttfamily \#define handle\+\_\+abort(\begin{DoxyParamCaption}\item[{}]{\textbf{ h} }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        \textcolor{keywordflow}{do} \{                                                    \(\backslash\)}
\DoxyCodeLine{                h-\/>shift\_reg = fast\_abort[h-\/>ffbit\_shift -\/ 1]; \(\backslash\)}
\DoxyCodeLine{                h-\/>hdlc\_bits1 = h-\/>ffbit\_shift -\/ 2;            \(\backslash\)}
\DoxyCodeLine{                if (h-\/>hdlc\_bits1 < 0)                         \(\backslash\)}
\DoxyCodeLine{                        h-\/>hdlc\_bits1 = 0;                      \(\backslash\)}
\DoxyCodeLine{                h-\/>data\_bits = h-\/>ffbit\_shift -\/ 1;             \(\backslash\)}
\DoxyCodeLine{                h-\/>state = HDLC\_GET\_DATA;                  \(\backslash\)}
\DoxyCodeLine{                h-\/>data\_received = 0;                           \(\backslash\)}
\DoxyCodeLine{        \} \textcolor{keywordflow}{while} (0)}

\end{DoxyCode}
\mbox{\label{isdnhdlc_8c_a9e596f205642177fa0a0b1f0b83cb5e8}} 
\index{isdnhdlc.c@{isdnhdlc.c}!handle\_fast\_flag@{handle\_fast\_flag}}
\index{handle\_fast\_flag@{handle\_fast\_flag}!isdnhdlc.c@{isdnhdlc.c}}
\doxysubsubsection{handle\_fast\_flag}
{\footnotesize\ttfamily \#define handle\+\_\+fast\+\_\+flag(\begin{DoxyParamCaption}\item[{}]{\textbf{ h} }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        \textcolor{keywordflow}{do} \{                                                            \(\backslash\)}
\DoxyCodeLine{                if (h-\/>cbin == fast\_flag[h-\/>bit\_shift]) \{             \(\backslash\)}
\DoxyCodeLine{                        h-\/>ffvalue = fast\_flag\_value[h-\/>bit\_shift];    \(\backslash\)}
\DoxyCodeLine{                        h-\/>state = HDLC\_FAST\_FLAG;                        \(\backslash\)}
\DoxyCodeLine{                        h-\/>ffbit\_shift = h-\/>bit\_shift;                 \(\backslash\)}
\DoxyCodeLine{                        h-\/>bit\_shift = 1;                               \(\backslash\)}
\DoxyCodeLine{                \} \textcolor{keywordflow}{else} \{                                                \(\backslash\)}
\DoxyCodeLine{                        h-\/>state = HDLC\_GET\_DATA;                  \(\backslash\)}
\DoxyCodeLine{                        h-\/>data\_received = 0;                           \(\backslash\)}
\DoxyCodeLine{                \}                                                       \(\backslash\)}
\DoxyCodeLine{        \} \textcolor{keywordflow}{while} (0)}

\end{DoxyCode}


\doxysubsection{Enumeration Type Documentation}
\mbox{\label{isdnhdlc_8c_a458e651af6690959efa2afb96be7d609}} 
\doxysubsubsection{anonymous enum}
{\footnotesize\ttfamily anonymous enum}

\begin{DoxyEnumFields}{Enumerator}
\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_FAST\_IDLE@{HDLC\_FAST\_IDLE}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_FAST\_IDLE@{HDLC\_FAST\_IDLE}}}\mbox{\label{isdnhdlc_8c_a458e651af6690959efa2afb96be7d609af2e8d8b742ed93f1ccae99392fb103e9}} 
HDLC\+\_\+\+FAST\+\_\+\+IDLE&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_GET\_FLAG\_B0@{HDLC\_GET\_FLAG\_B0}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_GET\_FLAG\_B0@{HDLC\_GET\_FLAG\_B0}}}\mbox{\label{isdnhdlc_8c_a458e651af6690959efa2afb96be7d609a5037b68183c53025dfbb5abe755549d2}} 
HDLC\+\_\+\+GET\+\_\+\+FLAG\+\_\+\+B0&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_GETFLAG\_B1A6@{HDLC\_GETFLAG\_B1A6}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_GETFLAG\_B1A6@{HDLC\_GETFLAG\_B1A6}}}\mbox{\label{isdnhdlc_8c_a458e651af6690959efa2afb96be7d609a49d08d7b9919b1e3162d80d7ed8c84da}} 
HDLC\+\_\+\+GETFLAG\+\_\+\+B1\+A6&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_GETFLAG\_B7@{HDLC\_GETFLAG\_B7}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_GETFLAG\_B7@{HDLC\_GETFLAG\_B7}}}\mbox{\label{isdnhdlc_8c_a458e651af6690959efa2afb96be7d609a573bef12dcd5d1fe05660391bcbebc33}} 
HDLC\+\_\+\+GETFLAG\+\_\+\+B7&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_GET\_DATA@{HDLC\_GET\_DATA}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_GET\_DATA@{HDLC\_GET\_DATA}}}\mbox{\label{isdnhdlc_8c_a458e651af6690959efa2afb96be7d609ac8d91e0fd825206d0021593c7a0e963b}} 
HDLC\+\_\+\+GET\+\_\+\+DATA&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_FAST\_FLAG@{HDLC\_FAST\_FLAG}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_FAST\_FLAG@{HDLC\_FAST\_FLAG}}}\mbox{\label{isdnhdlc_8c_a458e651af6690959efa2afb96be7d609a1565c33476d4685025df6ece33184a3d}} 
HDLC\+\_\+\+FAST\+\_\+\+FLAG&\\
\hline

\end{DoxyEnumFields}
\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562}} 
\doxysubsubsection{anonymous enum}
{\footnotesize\ttfamily anonymous enum}

\begin{DoxyEnumFields}{Enumerator}
\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_DATA@{HDLC\_SEND\_DATA}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_DATA@{HDLC\_SEND\_DATA}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562a8492bb354a5f35d47c98e39a460f6042}} 
HDLC\+\_\+\+SEND\+\_\+\+DATA&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_CRC1@{HDLC\_SEND\_CRC1}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_CRC1@{HDLC\_SEND\_CRC1}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562afc8b49708b57163b2d06a51f4f8bb85d}} 
HDLC\+\_\+\+SEND\+\_\+\+CRC1&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_FAST\_FLAG@{HDLC\_SEND\_FAST\_FLAG}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_FAST\_FLAG@{HDLC\_SEND\_FAST\_FLAG}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562ac7e49f9bff412da2659ac318f0a75370}} 
HDLC\+\_\+\+SEND\+\_\+\+FAST\+\_\+\+FLAG&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_FIRST\_FLAG@{HDLC\_SEND\_FIRST\_FLAG}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_FIRST\_FLAG@{HDLC\_SEND\_FIRST\_FLAG}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562a231e21b9780b3b3ee53ed83b6701ec96}} 
HDLC\+\_\+\+SEND\+\_\+\+FIRST\+\_\+\+FLAG&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_CRC2@{HDLC\_SEND\_CRC2}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_CRC2@{HDLC\_SEND\_CRC2}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562ab359ba643b879cbeac272ddc240ae9f0}} 
HDLC\+\_\+\+SEND\+\_\+\+CRC2&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_CLOSING\_FLAG@{HDLC\_SEND\_CLOSING\_FLAG}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_CLOSING\_FLAG@{HDLC\_SEND\_CLOSING\_FLAG}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562a7191b7ca73287ddf4b1f7b6793636da8}} 
HDLC\+\_\+\+SEND\+\_\+\+CLOSING\+\_\+\+FLAG&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_IDLE1@{HDLC\_SEND\_IDLE1}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_IDLE1@{HDLC\_SEND\_IDLE1}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562abae4fa6ddd9876da09d8d9c48f429e8c}} 
HDLC\+\_\+\+SEND\+\_\+\+IDLE1&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SEND\_FAST\_IDLE@{HDLC\_SEND\_FAST\_IDLE}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SEND\_FAST\_IDLE@{HDLC\_SEND\_FAST\_IDLE}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562a1a3a6c11b8c5dd59c9a46d5caed4835c}} 
HDLC\+\_\+\+SEND\+\_\+\+FAST\+\_\+\+IDLE&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SENDFLAG\_B0@{HDLC\_SENDFLAG\_B0}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SENDFLAG\_B0@{HDLC\_SENDFLAG\_B0}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562a1ca2046e201454b8bc2e38c2d7b54c17}} 
HDLC\+\_\+\+SENDFLAG\+\_\+\+B0&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SENDFLAG\_B1A6@{HDLC\_SENDFLAG\_B1A6}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SENDFLAG\_B1A6@{HDLC\_SENDFLAG\_B1A6}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562a2d3f45a4ebd13d409792d0ccf96d1c78}} 
HDLC\+\_\+\+SENDFLAG\+\_\+\+B1\+A6&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SENDFLAG\_B7@{HDLC\_SENDFLAG\_B7}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SENDFLAG\_B7@{HDLC\_SENDFLAG\_B7}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562afb1c2f38d91effdf7dc54e559b5249fa}} 
HDLC\+\_\+\+SENDFLAG\+\_\+\+B7&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{STOPPED@{STOPPED}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!STOPPED@{STOPPED}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562a948b2aee15f52b421fa4770c47bcfe8c}} 
STOPPED&\\
\hline

\raisebox{\heightof{T}}[0pt][0pt]{\index{HDLC\_SENDFLAG\_ONE@{HDLC\_SENDFLAG\_ONE}!isdnhdlc.c@{isdnhdlc.c}}\index{isdnhdlc.c@{isdnhdlc.c}!HDLC\_SENDFLAG\_ONE@{HDLC\_SENDFLAG\_ONE}}}\mbox{\label{isdnhdlc_8c_a1f9aebf1de3ebbf4283a4dcf73308562ad2ca1b245ee93f1750ca27920d636b16}} 
HDLC\+\_\+\+SENDFLAG\+\_\+\+ONE&\\
\hline

\end{DoxyEnumFields}


\doxysubsection{Function Documentation}
\mbox{\label{isdnhdlc_8c_a658be0139a8c3afd3f06cba38127b136}} 
\index{isdnhdlc.c@{isdnhdlc.c}!check\_frame@{check\_frame}}
\index{check\_frame@{check\_frame}!isdnhdlc.c@{isdnhdlc.c}}
\doxysubsubsection{check\_frame()}
{\footnotesize\ttfamily static int check\+\_\+frame (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars} $\ast$}]{hdlc }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



References \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::crc}, \textbf{ osmo\+\_\+isdnhdlc\+\_\+vars\+::dstpos}, \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+CRC\+\_\+\+ERROR}, and \textbf{ OSMO\+\_\+\+HDLC\+\_\+\+FRAMING\+\_\+\+ERROR}.



Referenced by \textbf{ osmo\+\_\+isdnhdlc\+\_\+decode()}.

\mbox{\label{isdnhdlc_8c_a7b51c27274ca2cccf23b4e868c7b6710}} 
\index{isdnhdlc.c@{isdnhdlc.c}!osmo\_isdnhdlc\_decode@{osmo\_isdnhdlc\_decode}}
\index{osmo\_isdnhdlc\_decode@{osmo\_isdnhdlc\_decode}!isdnhdlc.c@{isdnhdlc.c}}
\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_8c_a1b8eb0afa747804742eab4c1d59494c2}} 
\index{isdnhdlc.c@{isdnhdlc.c}!osmo\_isdnhdlc\_encode@{osmo\_isdnhdlc\_encode}}
\index{osmo\_isdnhdlc\_encode@{osmo\_isdnhdlc\_encode}!isdnhdlc.c@{isdnhdlc.c}}
\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_8c_abe1a5cfbb77cc0324b1ac506cbc8967d}} 
\index{isdnhdlc.c@{isdnhdlc.c}!osmo\_isdnhdlc\_out\_init@{osmo\_isdnhdlc\_out\_init}}
\index{osmo\_isdnhdlc\_out\_init@{osmo\_isdnhdlc\_out\_init}!isdnhdlc.c@{isdnhdlc.c}}
\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_8c_a98822a5ed1411cc5e7261f1e1e991152}} 
\index{isdnhdlc.c@{isdnhdlc.c}!osmo\_isdnhdlc\_rcv\_init@{osmo\_isdnhdlc\_rcv\_init}}
\index{osmo\_isdnhdlc\_rcv\_init@{osmo\_isdnhdlc\_rcv\_init}!isdnhdlc.c@{isdnhdlc.c}}
\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}.

