\doxysection{gprs\+\_\+ns.\+h}
\label{gprs__ns_8h_source}\index{include/osmocom/gprs/gprs\_ns.h@{include/osmocom/gprs/gprs\_ns.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{3 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{4 }
\DoxyCodeLine{5 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{6 }
\DoxyCodeLine{7 \textcolor{comment}{/* Our Implementation */}}
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <netinet/in.h>}}
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{10 \textcolor{preprocessor}{\#include <osmocom/core/msgb.h>}}
\DoxyCodeLine{11 \textcolor{preprocessor}{\#include <osmocom/core/timer.h>}}
\DoxyCodeLine{12 \textcolor{preprocessor}{\#include <osmocom/core/select.h>}}
\DoxyCodeLine{13 \textcolor{preprocessor}{\#include <osmocom/gprs/gprs\_msgb.h>}}
\DoxyCodeLine{14 }
\DoxyCodeLine{15 \textcolor{preprocessor}{\#include <osmocom/gprs/protocol/gsm\_08\_16.h>}}
\DoxyCodeLine{16 }
\DoxyCodeLine{17 \textcolor{preprocessor}{\#define NS\_TIMERS\_COUNT 8}}
\DoxyCodeLine{18 \textcolor{preprocessor}{\#define NS\_TIMERS "{}(tns-\/block|tns-\/block-\/retries|tns-\/reset|tns-\/reset-\/retries|tns-\/test|tns-\/alive|tns-\/alive-\/retries|tsns-\/prov)"{}}}
\DoxyCodeLine{19 \textcolor{preprocessor}{\#define NS\_TIMERS\_HELP  \(\backslash\)}}
\DoxyCodeLine{20 \textcolor{preprocessor}{        "{}(un)blocking Timer (Tns-\/block) timeout\(\backslash\)n"{}}              \(\backslash\)}
\DoxyCodeLine{21         "{}(un)blocking Timer (Tns-\/block) number of retries\(\backslash\)n"{}    \(\backslash\)}
\DoxyCodeLine{22         "{}Reset Timer (Tns-\/reset) timeout\(\backslash\)n"{}                     \(\backslash\)}
\DoxyCodeLine{23         "{}Reset Timer (Tns-\/reset) number of retries\(\backslash\)n"{}           \(\backslash\)}
\DoxyCodeLine{24         "{}Test Timer (Tns-\/test) timeout\(\backslash\)n"{}                       \(\backslash\)}
\DoxyCodeLine{25         "{}Alive Timer (Tns-\/alive) timeout\(\backslash\)n"{}                     \(\backslash\)}
\DoxyCodeLine{26         "{}Alive Timer (Tns-\/alive) number of retries\(\backslash\)n"{}           \(\backslash\)}
\DoxyCodeLine{27         "{}SNS Provision Timer (Tsns-\/prov) timeout\(\backslash\)n"{}}
\DoxyCodeLine{28 }
\DoxyCodeLine{29 \textcolor{comment}{/* Educated guess -\/ LLC user payload is 1500 bytes plus possible headers */}}
\DoxyCodeLine{30 \textcolor{preprocessor}{\#define NS\_ALLOC\_SIZE   3072}}
\DoxyCodeLine{31 \textcolor{preprocessor}{\#define NS\_ALLOC\_HEADROOM 20}}
\DoxyCodeLine{32 }
\DoxyCodeLine{33 \textcolor{keyword}{enum} ns\_timeout \{}
\DoxyCodeLine{34         NS\_TOUT\_TNS\_BLOCK,}
\DoxyCodeLine{35         NS\_TOUT\_TNS\_BLOCK\_RETRIES,}
\DoxyCodeLine{36         NS\_TOUT\_TNS\_RESET,}
\DoxyCodeLine{37         NS\_TOUT\_TNS\_RESET\_RETRIES,}
\DoxyCodeLine{38         NS\_TOUT\_TNS\_TEST,}
\DoxyCodeLine{39         NS\_TOUT\_TNS\_ALIVE,}
\DoxyCodeLine{40         NS\_TOUT\_TNS\_ALIVE\_RETRIES,}
\DoxyCodeLine{41         NS\_TOUT\_TSNS\_PROV,}
\DoxyCodeLine{42 \};}
\DoxyCodeLine{43 }
\DoxyCodeLine{44 \textcolor{preprocessor}{\#define NSE\_S\_BLOCKED   0x0001}}
\DoxyCodeLine{45 \textcolor{preprocessor}{\#define NSE\_S\_ALIVE     0x0002}}
\DoxyCodeLine{46 \textcolor{preprocessor}{\#define NSE\_S\_RESET     0x0004}}
\DoxyCodeLine{47 }
\DoxyCodeLine{48 \textcolor{preprocessor}{\#define NS\_DESC\_B(st) ((st) \& NSE\_S\_BLOCKED ? "{}BLOCKED"{}} : "{}UNBLOCKED"{})}
\DoxyCodeLine{49 \textcolor{preprocessor}{\#define NS\_DESC\_A(st) ((st) \& NSE\_S\_ALIVE ? "{}ALIVE"{}} : "{}DEAD"{})}
\DoxyCodeLine{50 \textcolor{preprocessor}{\#define NS\_DESC\_R(st) ((st) \& NSE\_S\_RESET ? "{}RESET"{}} : "{}UNRESET"{})}
\DoxyCodeLine{51 }
\DoxyCodeLine{53 \textcolor{keyword}{enum} gprs\_ns\_ll \{}
\DoxyCodeLine{54         GPRS\_NS\_LL\_UDP,           }
\DoxyCodeLine{55         GPRS\_NS\_LL\_E1,             }
\DoxyCodeLine{56         GPRS\_NS\_LL\_FR\_GRE,     }
\DoxyCodeLine{57 \};}
\DoxyCodeLine{58 }
\DoxyCodeLine{60 \textcolor{keyword}{enum} gprs\_ns\_evt \{}
\DoxyCodeLine{61         GPRS\_NS\_EVT\_UNIT\_DATA,}
\DoxyCodeLine{62 \};}
\DoxyCodeLine{63 }
\DoxyCodeLine{65 \textcolor{keyword}{enum} gprs\_ns\_cs \{}
\DoxyCodeLine{66         GPRS\_NS\_CS\_CREATED,     }
\DoxyCodeLine{67         GPRS\_NS\_CS\_FOUND,       }
\DoxyCodeLine{68         GPRS\_NS\_CS\_REJECTED,    }
\DoxyCodeLine{69         GPRS\_NS\_CS\_SKIPPED,     }
\DoxyCodeLine{70         GPRS\_NS\_CS\_ERROR,       }
\DoxyCodeLine{71 \};}
\DoxyCodeLine{72 }
\DoxyCodeLine{73 \textcolor{keyword}{struct }gprs\_nsvc;}
\DoxyCodeLine{75 \textcolor{keyword}{typedef} \textcolor{keywordtype}{int} gprs\_ns\_cb\_t(\textcolor{keyword}{enum} gprs\_ns\_evt event, \textcolor{keyword}{struct} gprs\_nsvc *nsvc,}
\DoxyCodeLine{76                          \textcolor{keyword}{struct} msgb *msg, uint16\_t bvci);}
\DoxyCodeLine{77 }
\DoxyCodeLine{79 \textcolor{keyword}{struct }gprs\_ns\_inst \{}
\DoxyCodeLine{81         gprs\_ns\_cb\_t *cb;}
\DoxyCodeLine{82 }
\DoxyCodeLine{84         \textcolor{keyword}{struct }llist\_head gprs\_nsvcs;}
\DoxyCodeLine{85 }
\DoxyCodeLine{88         \textcolor{keyword}{struct }gprs\_nsvc *unknown\_nsvc;}
\DoxyCodeLine{89 }
\DoxyCodeLine{90         uint16\_t timeout[NS\_TIMERS\_COUNT];}
\DoxyCodeLine{91 }
\DoxyCodeLine{93         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{94                 \textcolor{keyword}{struct }osmo\_fd fd;}
\DoxyCodeLine{95                 uint32\_t local\_ip;}
\DoxyCodeLine{96                 uint16\_t local\_port;}
\DoxyCodeLine{97                 uint32\_t remote\_ip;}
\DoxyCodeLine{98                 uint16\_t remote\_port;}
\DoxyCodeLine{99                 \textcolor{keywordtype}{int} dscp;}
\DoxyCodeLine{101                 \textcolor{keywordtype}{bool} use\_reset\_block\_unblock;}
\DoxyCodeLine{102         \} nsip;}
\DoxyCodeLine{104         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{105                 \textcolor{keyword}{struct }osmo\_fd fd;}
\DoxyCodeLine{106                 uint32\_t local\_ip;}
\DoxyCodeLine{107                 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} enabled:1;}
\DoxyCodeLine{108         \} frgre;}
\DoxyCodeLine{109 }
\DoxyCodeLine{110         \textcolor{keyword}{struct }osmo\_fsm\_inst *bss\_sns\_fi;}
\DoxyCodeLine{111 \};}
\DoxyCodeLine{112 }
\DoxyCodeLine{113 \textcolor{keyword}{enum} nsvc\_timer\_mode \{}
\DoxyCodeLine{114         \textcolor{comment}{/* standard timers */}}
\DoxyCodeLine{115         NSVC\_TIMER\_TNS\_TEST,}
\DoxyCodeLine{116         NSVC\_TIMER\_TNS\_ALIVE,}
\DoxyCodeLine{117         NSVC\_TIMER\_TNS\_RESET,}
\DoxyCodeLine{118         \_NSVC\_TIMER\_NR,}
\DoxyCodeLine{119 \};}
\DoxyCodeLine{120 }
\DoxyCodeLine{122 \textcolor{keyword}{struct }gprs\_nsvc \{}
\DoxyCodeLine{124         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{126         \textcolor{keyword}{struct }gprs\_ns\_inst *nsi;}
\DoxyCodeLine{127 }
\DoxyCodeLine{128         uint16\_t nsei;      }
\DoxyCodeLine{129         uint16\_t nsvci;    }
\DoxyCodeLine{131         uint32\_t state;}
\DoxyCodeLine{132         uint32\_t remote\_state;}
\DoxyCodeLine{133 }
\DoxyCodeLine{134         \textcolor{keyword}{struct }osmo\_timer\_list timer;}
\DoxyCodeLine{135         \textcolor{keyword}{enum} nsvc\_timer\_mode timer\_mode;}
\DoxyCodeLine{136         \textcolor{keyword}{struct }timeval timer\_started;}
\DoxyCodeLine{137         \textcolor{keywordtype}{int} alive\_retries;}
\DoxyCodeLine{138 }
\DoxyCodeLine{139         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} remote\_end\_is\_sgsn:1;}
\DoxyCodeLine{140         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} persistent:1;}
\DoxyCodeLine{141         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} nsvci\_is\_valid:1;}
\DoxyCodeLine{142 }
\DoxyCodeLine{143         \textcolor{keyword}{struct }rate\_ctr\_group *ctrg;}
\DoxyCodeLine{144         \textcolor{keyword}{struct }osmo\_stat\_item\_group *statg;}
\DoxyCodeLine{145 }
\DoxyCodeLine{147         \textcolor{keyword}{enum} gprs\_ns\_ll ll;}
\DoxyCodeLine{148 }
\DoxyCodeLine{151         \textcolor{keyword}{union }\{}
\DoxyCodeLine{152                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{153                         \textcolor{keyword}{struct }sockaddr\_in bts\_addr;}
\DoxyCodeLine{154                 \} ip;}
\DoxyCodeLine{155                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{156                         \textcolor{keyword}{struct }sockaddr\_in bts\_addr;}
\DoxyCodeLine{157                 \} frgre;}
\DoxyCodeLine{158         \};}
\DoxyCodeLine{160         uint8\_t sig\_weight;}
\DoxyCodeLine{162         uint8\_t data\_weight;}
\DoxyCodeLine{163 \};}
\DoxyCodeLine{164 }
\DoxyCodeLine{165 \textcolor{comment}{/* Create a new NS protocol instance */}}
\DoxyCodeLine{166 \textcolor{keyword}{struct }gprs\_ns\_inst *gprs\_ns\_instantiate(gprs\_ns\_cb\_t *cb, \textcolor{keywordtype}{void} *ctx);}
\DoxyCodeLine{167 }
\DoxyCodeLine{168 \textcolor{comment}{/* Close a NS protocol instance */}}
\DoxyCodeLine{169 \textcolor{keywordtype}{void} gprs\_ns\_close(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi);}
\DoxyCodeLine{170 }
\DoxyCodeLine{171 \textcolor{comment}{/* Close and Destroy a NS protocol instance */}}
\DoxyCodeLine{172 \textcolor{keywordtype}{void} gprs\_ns\_destroy(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi);}
\DoxyCodeLine{173 }
\DoxyCodeLine{174 \textcolor{comment}{/* Listen for incoming GPRS packets via NS/UDP */}}
\DoxyCodeLine{175 \textcolor{keywordtype}{int} gprs\_ns\_nsip\_listen(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi);}
\DoxyCodeLine{176 }
\DoxyCodeLine{177 \textcolor{comment}{/* Establish a connection (from the BSS) to the SGSN */}}
\DoxyCodeLine{178 \textcolor{keyword}{struct }gprs\_nsvc *gprs\_ns\_nsip\_connect(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi,}
\DoxyCodeLine{179                                         \textcolor{keyword}{struct} sockaddr\_in *dest,}
\DoxyCodeLine{180                                         uint16\_t nsei, uint16\_t nsvci);}
\DoxyCodeLine{181 }
\DoxyCodeLine{182 \textcolor{comment}{/* Establish a connection (from the BSS) to the SGSN using IP SNS */}}
\DoxyCodeLine{183 \textcolor{keyword}{struct }gprs\_nsvc *gprs\_ns\_nsip\_connect\_sns(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi, \textcolor{keyword}{struct} sockaddr\_in *dest,}
\DoxyCodeLine{184                                            uint16\_t nsei, uint16\_t nsvci);}
\DoxyCodeLine{185 }
\DoxyCodeLine{186 \textcolor{keyword}{struct }sockaddr\_in;}
\DoxyCodeLine{187 }
\DoxyCodeLine{188 \textcolor{comment}{/* main function for higher layers (BSSGP) to send NS messages */}}
\DoxyCodeLine{189 \textcolor{keywordtype}{int} gprs\_ns\_sendmsg(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi, \textcolor{keyword}{struct} msgb *msg);}
\DoxyCodeLine{190 }
\DoxyCodeLine{191 \textcolor{comment}{/* Receive incoming NS message from underlying transport layer */}}
\DoxyCodeLine{192 \textcolor{keywordtype}{int} gprs\_ns\_rcvmsg(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi, \textcolor{keyword}{struct} msgb *msg,}
\DoxyCodeLine{193                    \textcolor{keyword}{struct} sockaddr\_in *saddr, \textcolor{keyword}{enum} gprs\_ns\_ll ll);}
\DoxyCodeLine{194 }
\DoxyCodeLine{195 }
\DoxyCodeLine{196 \textcolor{keywordtype}{int} gprs\_ns\_tx\_alive(\textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{197 \textcolor{keywordtype}{int} gprs\_ns\_tx\_alive\_ack(\textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{198 \textcolor{keywordtype}{int} gprs\_ns\_tx\_reset(\textcolor{keyword}{struct} gprs\_nsvc *nsvc, uint8\_t cause);}
\DoxyCodeLine{199 \textcolor{keywordtype}{int} gprs\_ns\_tx\_block(\textcolor{keyword}{struct} gprs\_nsvc *nsvc, uint8\_t cause);}
\DoxyCodeLine{200 \textcolor{keywordtype}{int} gprs\_ns\_tx\_unblock(\textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{201 }
\DoxyCodeLine{202 \textcolor{comment}{/* Listen for incoming GPRS packets via NS/FR/GRE */}}
\DoxyCodeLine{203 \textcolor{keywordtype}{int} gprs\_ns\_frgre\_listen(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi);}
\DoxyCodeLine{204 }
\DoxyCodeLine{205 \textcolor{keyword}{struct }gprs\_nsvc *gprs\_nsvc\_create2(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi, uint16\_t nsvci,}
\DoxyCodeLine{206                                     uint8\_t sig\_weight, uint8\_t data\_weight);}
\DoxyCodeLine{207 \textcolor{keywordtype}{void} gprs\_nsvc\_delete(\textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{208 \textcolor{keyword}{struct }gprs\_nsvc *gprs\_nsvc\_by\_nsei(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi, uint16\_t nsei);}
\DoxyCodeLine{209 \textcolor{keyword}{struct }gprs\_nsvc *gprs\_nsvc\_by\_nsvci(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi, uint16\_t nsvci);}
\DoxyCodeLine{210 \textcolor{keyword}{struct }gprs\_nsvc *gprs\_nsvc\_by\_rem\_addr(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi, \textcolor{keyword}{const} \textcolor{keyword}{struct} sockaddr\_in *sin);}
\DoxyCodeLine{211 }
\DoxyCodeLine{212 \textcolor{comment}{/* Initiate a RESET procedure (including timer start, ...)*/}}
\DoxyCodeLine{213 \textcolor{keywordtype}{int} gprs\_nsvc\_reset(\textcolor{keyword}{struct} gprs\_nsvc *nsvc, uint8\_t cause);}
\DoxyCodeLine{214 }
\DoxyCodeLine{215 \textcolor{comment}{/* Add NS-\/specific VTY stuff */}}
\DoxyCodeLine{216 \textcolor{keywordtype}{int} gprs\_ns\_vty\_init(\textcolor{keyword}{struct} gprs\_ns\_inst *nsi);}
\DoxyCodeLine{217 }
\DoxyCodeLine{218 \textcolor{comment}{/* Resturn peer info as string (NOTE: the buffer is allocated statically) */}}
\DoxyCodeLine{219 \textcolor{keyword}{const} \textcolor{keywordtype}{char} *gprs\_ns\_ll\_str(\textcolor{keyword}{const} \textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{220 \textcolor{comment}{/* Return peer info in user-\/supplied buffer */}}
\DoxyCodeLine{221 \textcolor{keywordtype}{char} *gprs\_ns\_ll\_str\_buf(\textcolor{keywordtype}{char} *buf, \textcolor{keywordtype}{size\_t} buf\_len, \textcolor{keyword}{const} \textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{222 \textcolor{keywordtype}{char} *gprs\_ns\_ll\_str\_c(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx, \textcolor{keyword}{const} \textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{223 }
\DoxyCodeLine{224 \textcolor{comment}{/* Copy the link layer info from other into nsvc */}}
\DoxyCodeLine{225 \textcolor{keywordtype}{void} gprs\_ns\_ll\_copy(\textcolor{keyword}{struct} gprs\_nsvc *nsvc, \textcolor{keyword}{struct} gprs\_nsvc *other);}
\DoxyCodeLine{226 }
\DoxyCodeLine{227 \textcolor{comment}{/* Clear the link layer info (will never match a real link then) */}}
\DoxyCodeLine{228 \textcolor{keywordtype}{void} gprs\_ns\_ll\_clear(\textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{229 }
\DoxyCodeLine{230 \textcolor{keyword}{struct }msgb *gprs\_ns\_msgb\_alloc(\textcolor{keywordtype}{void});}
\DoxyCodeLine{231 }
\DoxyCodeLine{232 \textcolor{keyword}{enum} signal\_ns \{}
\DoxyCodeLine{233         S\_NS\_RESET,}
\DoxyCodeLine{234         S\_NS\_BLOCK,}
\DoxyCodeLine{235         S\_NS\_UNBLOCK,}
\DoxyCodeLine{236         S\_NS\_ALIVE\_EXP,   \textcolor{comment}{/* Tns-\/alive expired more than N times */}}
\DoxyCodeLine{237         S\_NS\_REPLACED, \textcolor{comment}{/* nsvc object is replaced (sets old\_nsvc) */}}
\DoxyCodeLine{238         S\_NS\_MISMATCH, \textcolor{comment}{/* got an unexpected IE (sets msg, pdu\_type, ie\_type) */}}
\DoxyCodeLine{239         S\_SNS\_CONFIGURED, \textcolor{comment}{/* IP-\/SNS configuration completed */}}
\DoxyCodeLine{240 \};}
\DoxyCodeLine{241 }
\DoxyCodeLine{242 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }value\_string gprs\_ns\_signal\_ns\_names[];}
\DoxyCodeLine{243 \textcolor{keyword}{const} \textcolor{keywordtype}{char} *gprs\_ns\_cause\_str(\textcolor{keyword}{enum} ns\_cause cause);}
\DoxyCodeLine{244 }
\DoxyCodeLine{245 \textcolor{keyword}{struct }ns\_signal\_data \{}
\DoxyCodeLine{246         \textcolor{keyword}{struct }gprs\_nsvc *nsvc;}
\DoxyCodeLine{247         \textcolor{keyword}{struct }gprs\_nsvc *old\_nsvc;}
\DoxyCodeLine{248         uint8\_t cause;}
\DoxyCodeLine{249         uint8\_t pdu\_type;}
\DoxyCodeLine{250         uint8\_t ie\_type;}
\DoxyCodeLine{251         \textcolor{keyword}{struct }msgb *msg;}
\DoxyCodeLine{252 \};}
\DoxyCodeLine{253 }
\DoxyCodeLine{254 \textcolor{keywordtype}{void} gprs\_ns\_set\_log\_ss(\textcolor{keywordtype}{int} ss);}
\DoxyCodeLine{255 }
\DoxyCodeLine{256 \textcolor{keywordtype}{char} *gprs\_nsvc\_state\_append(\textcolor{keywordtype}{char} *s, \textcolor{keyword}{struct} gprs\_nsvc *nsvc);}
\DoxyCodeLine{257 }

\end{DoxyCode}
