\doxysection{gsm0502.\+h}
\label{gsm0502_8h_source}\index{include/osmocom/gsm/gsm0502.h@{include/osmocom/gsm/gsm0502.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{6 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{7 }
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{9 }
\DoxyCodeLine{10 \textcolor{preprocessor}{\#include <osmocom/gsm/protocol/gsm\_04\_08.h>}}
\DoxyCodeLine{11 \textcolor{preprocessor}{\#include <osmocom/gsm/protocol/gsm\_08\_58.h>}}
\DoxyCodeLine{12 }
\DoxyCodeLine{13 \textcolor{comment}{/* 4.3.3 TDMA frame number : constants and modular arithmetic */}}
\DoxyCodeLine{14 \textcolor{preprocessor}{\#define GSM\_TDMA\_FN\_DURATION\_nS         4615384         }\textcolor{comment}{/* in 1e−9 seconds (approx) */}\textcolor{preprocessor}{}}
\DoxyCodeLine{15 \textcolor{preprocessor}{\#define GSM\_TDMA\_FN\_DURATION\_uS         4615            }\textcolor{comment}{/* in 1e-\/6 seconds (approx) */}\textcolor{preprocessor}{}}
\DoxyCodeLine{16 }
\DoxyCodeLine{17 \textcolor{preprocessor}{\#define GSM\_TDMA\_SUPERFRAME             (26 * 51)}}
\DoxyCodeLine{18 \textcolor{preprocessor}{\#define GSM\_TDMA\_HYPERFRAME             (2048 * GSM\_TDMA\_SUPERFRAME)}}
\DoxyCodeLine{19 }
\DoxyCodeLine{21 \textcolor{preprocessor}{\#define GSM\_TDMA\_FN\_SUM(a, b) \(\backslash\)}}
\DoxyCodeLine{22 \textcolor{preprocessor}{        (((a) + (b)) \% GSM\_TDMA\_HYPERFRAME)}}
\DoxyCodeLine{24 \textcolor{preprocessor}{\#define GSM\_TDMA\_FN\_SUB(a, b) \(\backslash\)}}
\DoxyCodeLine{25 \textcolor{preprocessor}{        (((a) + GSM\_TDMA\_HYPERFRAME -\/ (b)) \% GSM\_TDMA\_HYPERFRAME)}}
\DoxyCodeLine{27 \textcolor{preprocessor}{\#define GSM\_TDMA\_FN\_DIFF(a, b) \(\backslash\)}}
\DoxyCodeLine{28 \textcolor{preprocessor}{        OSMO\_MIN(GSM\_TDMA\_FN\_SUB(a, b), GSM\_TDMA\_FN\_SUB(b, a))}}
\DoxyCodeLine{29 }
\DoxyCodeLine{31 \textcolor{preprocessor}{\#define GSM\_TDMA\_FN\_INC(fn) \(\backslash\)}}
\DoxyCodeLine{32 \textcolor{preprocessor}{        ((fn) = GSM\_TDMA\_FN\_SUM((fn), 1))}}
\DoxyCodeLine{34 \textcolor{preprocessor}{\#define GSM\_TDMA\_FN\_DEC(fn) \(\backslash\)}}
\DoxyCodeLine{35 \textcolor{preprocessor}{        ((fn) = GSM\_TDMA\_FN\_SUB((fn), 1))}}
\DoxyCodeLine{36 }
\DoxyCodeLine{37 \textcolor{comment}{/* 5.2.3.1 Normal burst for GMSK (1 bit per symbol) */}}
\DoxyCodeLine{38 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_GMSK\_TAIL          3}}
\DoxyCodeLine{39 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_GMSK\_PAYLOAD       (2 * 58)}}
\DoxyCodeLine{40 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_GMSK\_TRAIN\_SEQ     26}}
\DoxyCodeLine{41 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_GMSK\_BURST         148  }\textcolor{comment}{/* without guard period */}\textcolor{preprocessor}{}}
\DoxyCodeLine{42 }
\DoxyCodeLine{43 \textcolor{comment}{/* 5.2.3.3 Normal burst for 8-\/PSK (3 bits per symbol) */}}
\DoxyCodeLine{44 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_8PSK\_TAIL          (GSM\_NBITS\_NB\_GMSK\_TAIL * 3)}}
\DoxyCodeLine{45 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_8PSK\_PAYLOAD       (GSM\_NBITS\_NB\_GMSK\_PAYLOAD * 3)}}
\DoxyCodeLine{46 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_8PSK\_TRAIN\_SEQ     (GSM\_NBITS\_NB\_GMSK\_TRAIN\_SEQ * 3)}}
\DoxyCodeLine{47 \textcolor{preprocessor}{\#define GSM\_NBITS\_NB\_8PSK\_BURST         (GSM\_NBITS\_NB\_GMSK\_BURST * 3)}}
\DoxyCodeLine{48 }
\DoxyCodeLine{49 \textcolor{comment}{/* 5.2.5 Synchronization burst (also GMSK) */}}
\DoxyCodeLine{50 \textcolor{preprocessor}{\#define GSM\_NBITS\_SB\_GMSK\_TAIL          GSM\_NBITS\_NB\_GMSK\_TAIL}}
\DoxyCodeLine{51 \textcolor{preprocessor}{\#define GSM\_NBITS\_SB\_GMSK\_PAYLOAD       (2 * 39)}}
\DoxyCodeLine{52 \textcolor{preprocessor}{\#define GSM\_NBITS\_SB\_GMSK\_ETRAIN\_SEQ    64}}
\DoxyCodeLine{53 \textcolor{preprocessor}{\#define GSM\_NBITS\_SB\_GMSK\_BURST         GSM\_NBITS\_NB\_GMSK\_BURST}}
\DoxyCodeLine{54 }
\DoxyCodeLine{55 \textcolor{comment}{/* 5.2.6 Dummy burst (also GMSK) */}}
\DoxyCodeLine{56 \textcolor{preprocessor}{\#define GSM\_NBITS\_DB\_GMSK\_TAIL          GSM\_NBITS\_NB\_GMSK\_TAIL}}
\DoxyCodeLine{57 \textcolor{preprocessor}{\#define GSM\_NBITS\_DB\_GMSK\_MIXED         142}}
\DoxyCodeLine{58 \textcolor{preprocessor}{\#define GSM\_NBITS\_DB\_GMSK\_BURST         GSM\_NBITS\_NB\_GMSK\_BURST}}
\DoxyCodeLine{59 }
\DoxyCodeLine{60 \textcolor{comment}{/* 5.2.7 Access burst (also GMSK) */}}
\DoxyCodeLine{61 \textcolor{preprocessor}{\#define GSM\_NBITS\_AB\_GMSK\_ETAIL         8}}
\DoxyCodeLine{62 \textcolor{preprocessor}{\#define GSM\_NBITS\_AB\_GMSK\_SYNCH\_SEQ     41}}
\DoxyCodeLine{63 \textcolor{preprocessor}{\#define GSM\_NBITS\_AB\_GMSK\_PAYLOAD       36}}
\DoxyCodeLine{64 \textcolor{preprocessor}{\#define GSM\_NBITS\_AB\_GMSK\_TAIL          GSM\_NBITS\_NB\_GMSK\_TAIL}}
\DoxyCodeLine{65 \textcolor{preprocessor}{\#define GSM\_NBITS\_AB\_GMSK\_BURST         GSM\_NBITS\_NB\_GMSK\_BURST}}
\DoxyCodeLine{66 }
\DoxyCodeLine{73 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{int} gsm0502\_fncmp(uint32\_t fn1, uint32\_t fn2)}
\DoxyCodeLine{74 \{}
\DoxyCodeLine{75         \textcolor{keyword}{const} uint32\_t thresh = GSM\_TDMA\_HYPERFRAME / 2;}
\DoxyCodeLine{76 }
\DoxyCodeLine{77         \textcolor{keywordflow}{if} (fn1 == fn2)}
\DoxyCodeLine{78                 \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{79         \textcolor{keywordflow}{if} ((fn1 < fn2 \&\& (fn2 -\/ fn1) < thresh) ||}
\DoxyCodeLine{80             (fn1 > fn2 \&\& (fn1 -\/ fn2) > thresh))}
\DoxyCodeLine{81                 \textcolor{keywordflow}{return} -\/1;}
\DoxyCodeLine{82 }
\DoxyCodeLine{83         \textcolor{keywordflow}{return} 1;}
\DoxyCodeLine{84 \}}
\DoxyCodeLine{85 }
\DoxyCodeLine{86 \textcolor{comment}{/* Table 5 Clause 7 TS 05.02 */}}
\DoxyCodeLine{87 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int}}
\DoxyCodeLine{88 gsm0502\_get\_n\_pag\_blocks(\textcolor{keyword}{const} \textcolor{keyword}{struct} gsm48\_control\_channel\_descr *chan\_desc)}
\DoxyCodeLine{89 \{}
\DoxyCodeLine{90         \textcolor{keywordflow}{if} (chan\_desc-\/>ccch\_conf == RSL\_BCCH\_CCCH\_CONF\_1\_C)}
\DoxyCodeLine{91                 \textcolor{keywordflow}{return} 3 -\/ chan\_desc-\/>bs\_ag\_blks\_res;}
\DoxyCodeLine{92         \textcolor{keywordflow}{else}}
\DoxyCodeLine{93                 \textcolor{keywordflow}{return} 9 -\/ chan\_desc-\/>bs\_ag\_blks\_res;}
\DoxyCodeLine{94 \}}
\DoxyCodeLine{95 }
\DoxyCodeLine{96 \textcolor{comment}{/* Chapter 6.5.2 of TS 05.02 */}}
\DoxyCodeLine{97 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int}}
\DoxyCodeLine{98 gsm0502\_get\_ccch\_group(uint64\_t imsi, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bs\_cc\_chans,}
\DoxyCodeLine{99                         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} n\_pag\_blocks)}
\DoxyCodeLine{100 \{}
\DoxyCodeLine{101         \textcolor{keywordflow}{return} (imsi \% 1000) \% (bs\_cc\_chans * n\_pag\_blocks) / n\_pag\_blocks;}
\DoxyCodeLine{102 \}}
\DoxyCodeLine{103 }
\DoxyCodeLine{104 \textcolor{comment}{/* Chapter 6.5.2 of TS 05.02 */}}
\DoxyCodeLine{105 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int}}
\DoxyCodeLine{106 gsm0502\_get\_paging\_group(uint64\_t imsi, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bs\_cc\_chans,}
\DoxyCodeLine{107                          \textcolor{keywordtype}{int} n\_pag\_blocks)}
\DoxyCodeLine{108 \{}
\DoxyCodeLine{109         \textcolor{keywordflow}{return} (imsi \% 1000) \% (bs\_cc\_chans * n\_pag\_blocks) \% n\_pag\_blocks;}
\DoxyCodeLine{110 \}}
\DoxyCodeLine{111 }
\DoxyCodeLine{112 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int}}
\DoxyCodeLine{113 gsm0502\_calc\_paging\_group(\textcolor{keyword}{const} \textcolor{keyword}{struct} gsm48\_control\_channel\_descr *chan\_desc, uint64\_t imsi);}
\DoxyCodeLine{114 }
\DoxyCodeLine{115 \textcolor{keyword}{enum} gsm0502\_fn\_remap\_channel \{}
\DoxyCodeLine{116         FN\_REMAP\_TCH\_F,}
\DoxyCodeLine{117         FN\_REMAP\_TCH\_H0,}
\DoxyCodeLine{118         FN\_REMAP\_TCH\_H1,}
\DoxyCodeLine{119         FN\_REMAP\_FACCH\_F,}
\DoxyCodeLine{120         FN\_REMAP\_FACCH\_H0,}
\DoxyCodeLine{121         FN\_REMAP\_FACCH\_H1,}
\DoxyCodeLine{122         FN\_REMAP\_MAX,}
\DoxyCodeLine{123 \};}
\DoxyCodeLine{124 }
\DoxyCodeLine{125 uint32\_t gsm0502\_fn\_remap(uint32\_t fn, \textcolor{keyword}{enum} gsm0502\_fn\_remap\_channel channel);}
\DoxyCodeLine{126 }
\DoxyCodeLine{127 uint16\_t gsm0502\_hop\_seq\_gen(\textcolor{keyword}{const} \textcolor{keyword}{struct} gsm\_time *t,}
\DoxyCodeLine{128                              uint8\_t hsn, uint8\_t maio,}
\DoxyCodeLine{129                              \textcolor{keywordtype}{size\_t} n, \textcolor{keyword}{const} uint16\_t *ma);}
\DoxyCodeLine{130 }
\DoxyCodeLine{131 \textcolor{keywordtype}{int} gsm0502\_fn2ccch\_block(uint32\_t fn);}
\DoxyCodeLine{132 }

\end{DoxyCode}
