2010-03-14 07:45:01 +00:00
|
|
|
#ifndef _GPRS_NS_H
|
|
|
|
#define _GPRS_NS_H
|
|
|
|
|
2010-05-02 09:26:34 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
/* Our Implementation */
|
|
|
|
#include <netinet/in.h>
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/linuxlist.h>
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/core/timer.h>
|
|
|
|
#include <osmocom/core/select.h>
|
2012-06-16 08:09:52 +00:00
|
|
|
#include <osmocom/gprs/gprs_msgb.h>
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2012-06-17 05:12:51 +00:00
|
|
|
#include <osmocom/gprs/protocol/gsm_08_16.h>
|
|
|
|
|
2010-05-12 17:19:53 +00:00
|
|
|
#define NS_TIMERS_COUNT 7
|
|
|
|
#define NS_TIMERS "(tns-block|tns-block-retries|tns-reset|tns-reset-retries|tns-test|tns-alive|tns-alive-retries)"
|
|
|
|
#define NS_TIMERS_HELP \
|
|
|
|
"(un)blocking Timer (Tns-block) timeout\n" \
|
|
|
|
"(un)blocking Timer (Tns-block) number of retries\n" \
|
|
|
|
"Reset Timer (Tns-reset) timeout\n" \
|
|
|
|
"Reset Timer (Tns-reset) number of retries\n" \
|
|
|
|
"Test Timer (Tns-test) timeout\n" \
|
2011-11-05 14:14:59 +00:00
|
|
|
"Alive Timer (Tns-alive) timeout\n" \
|
|
|
|
"Alive Timer (Tns-alive) number of retries\n"
|
2010-05-12 17:19:53 +00:00
|
|
|
|
|
|
|
enum ns_timeout {
|
|
|
|
NS_TOUT_TNS_BLOCK,
|
|
|
|
NS_TOUT_TNS_BLOCK_RETRIES,
|
|
|
|
NS_TOUT_TNS_RESET,
|
|
|
|
NS_TOUT_TNS_RESET_RETRIES,
|
|
|
|
NS_TOUT_TNS_TEST,
|
|
|
|
NS_TOUT_TNS_ALIVE,
|
|
|
|
NS_TOUT_TNS_ALIVE_RETRIES,
|
|
|
|
};
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
#define NSE_S_BLOCKED 0x0001
|
|
|
|
#define NSE_S_ALIVE 0x0002
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief Osmocom NS link layer types */
|
2010-05-01 09:28:43 +00:00
|
|
|
enum gprs_ns_ll {
|
2011-11-23 14:01:31 +00:00
|
|
|
GPRS_NS_LL_UDP, /*!< NS/UDP/IP */
|
|
|
|
GPRS_NS_LL_E1, /*!< NS/E1 */
|
|
|
|
GPRS_NS_LL_FR_GRE, /*!< NS/FR/GRE/IP */
|
2010-05-01 09:28:43 +00:00
|
|
|
};
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief Osmoco NS events */
|
2010-05-01 09:28:43 +00:00
|
|
|
enum gprs_ns_evt {
|
|
|
|
GPRS_NS_EVT_UNIT_DATA,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gprs_nsvc;
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief Osmocom GPRS callback function type */
|
2010-05-01 09:28:43 +00:00
|
|
|
typedef int gprs_ns_cb_t(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
|
2010-05-02 09:26:34 +00:00
|
|
|
struct msgb *msg, uint16_t bvci);
|
2010-05-01 09:28:43 +00:00
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief An instance of the NS protocol stack */
|
2010-05-01 09:28:43 +00:00
|
|
|
struct gprs_ns_inst {
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief callback to the user for incoming UNIT DATA IND */
|
2010-05-01 09:28:43 +00:00
|
|
|
gprs_ns_cb_t *cb;
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief linked lists of all NSVC in this instance */
|
2010-05-01 09:28:43 +00:00
|
|
|
struct llist_head gprs_nsvcs;
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief a NSVC object that's needed to deal with packets for
|
|
|
|
* unknown NSVC */
|
2010-05-13 11:58:08 +00:00
|
|
|
struct gprs_nsvc *unknown_nsvc;
|
|
|
|
|
2010-05-12 17:19:53 +00:00
|
|
|
uint16_t timeout[NS_TIMERS_COUNT];
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief NS-over-IP specific bits */
|
2010-05-19 12:38:50 +00:00
|
|
|
struct {
|
2011-05-06 10:11:23 +00:00
|
|
|
struct osmo_fd fd;
|
2010-05-19 13:09:09 +00:00
|
|
|
uint32_t local_ip;
|
|
|
|
uint16_t local_port;
|
2010-05-19 12:38:50 +00:00
|
|
|
} nsip;
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief NS-over-FR-over-GRE-over-IP specific bits */
|
2010-05-19 12:38:50 +00:00
|
|
|
struct {
|
2011-05-06 10:11:23 +00:00
|
|
|
struct osmo_fd fd;
|
2010-05-19 13:09:09 +00:00
|
|
|
uint32_t local_ip;
|
2012-03-02 13:14:33 +00:00
|
|
|
unsigned int enabled:1;
|
2010-05-19 12:38:50 +00:00
|
|
|
} frgre;
|
2010-05-01 09:28:43 +00:00
|
|
|
};
|
|
|
|
|
2010-05-03 18:16:13 +00:00
|
|
|
enum nsvc_timer_mode {
|
|
|
|
/* standard timers */
|
|
|
|
NSVC_TIMER_TNS_TEST,
|
|
|
|
NSVC_TIMER_TNS_ALIVE,
|
2010-05-03 18:55:10 +00:00
|
|
|
NSVC_TIMER_TNS_RESET,
|
|
|
|
_NSVC_TIMER_NR,
|
2010-05-03 18:16:13 +00:00
|
|
|
};
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief Structure representing a single NS-VC */
|
2010-04-30 18:26:32 +00:00
|
|
|
struct gprs_nsvc {
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief list of NS-VCs within NS Instance */
|
2010-04-30 18:26:32 +00:00
|
|
|
struct llist_head list;
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief pointer to NS Instance */
|
2010-04-30 18:26:32 +00:00
|
|
|
struct gprs_ns_inst *nsi;
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
uint16_t nsei; /*! \brief end-to-end significance */
|
|
|
|
uint16_t nsvci; /*! \brief uniquely identifies NS-VC at SGSN */
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2010-05-02 09:26:34 +00:00
|
|
|
uint32_t state;
|
|
|
|
uint32_t remote_state;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2011-05-06 10:11:06 +00:00
|
|
|
struct osmo_timer_list timer;
|
2010-05-03 18:16:13 +00:00
|
|
|
enum nsvc_timer_mode timer_mode;
|
2010-04-30 18:26:32 +00:00
|
|
|
int alive_retries;
|
|
|
|
|
2010-05-12 15:55:23 +00:00
|
|
|
unsigned int remote_end_is_sgsn:1;
|
|
|
|
unsigned int persistent:1;
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2010-05-13 09:45:07 +00:00
|
|
|
struct rate_ctr_group *ctrg;
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! \brief which link-layer are we based on? */
|
2010-05-19 12:38:50 +00:00
|
|
|
enum gprs_ns_ll ll;
|
|
|
|
|
2010-04-30 18:26:32 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
struct sockaddr_in bts_addr;
|
|
|
|
} ip;
|
2010-05-19 12:38:50 +00:00
|
|
|
struct {
|
|
|
|
struct sockaddr_in bts_addr;
|
|
|
|
} frgre;
|
2010-04-30 18:26:32 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2010-04-26 17:18:54 +00:00
|
|
|
/* Create a new NS protocol instance */
|
2012-06-16 08:40:42 +00:00
|
|
|
struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx);
|
2010-04-26 17:18:54 +00:00
|
|
|
|
|
|
|
/* Destroy a NS protocol instance */
|
|
|
|
void gprs_ns_destroy(struct gprs_ns_inst *nsi);
|
2010-03-14 07:45:01 +00:00
|
|
|
|
2010-05-19 12:38:50 +00:00
|
|
|
/* Listen for incoming GPRS packets via NS/UDP */
|
2010-05-19 13:09:09 +00:00
|
|
|
int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi);
|
2010-03-14 07:45:01 +00:00
|
|
|
|
2012-06-17 04:25:53 +00:00
|
|
|
/* Establish a connection (from the BSS) to the SGSN */
|
|
|
|
struct gprs_nsvc *gprs_ns_nsip_connect(struct gprs_ns_inst *nsi,
|
|
|
|
struct sockaddr_in *dest,
|
|
|
|
uint16_t nsei, uint16_t nsvci);
|
|
|
|
|
|
|
|
|
2010-04-26 17:18:54 +00:00
|
|
|
struct sockaddr_in;
|
|
|
|
|
|
|
|
/* main function for higher layers (BSSGP) to send NS messages */
|
2010-04-30 17:54:29 +00:00
|
|
|
int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg);
|
2010-04-26 17:18:54 +00:00
|
|
|
|
2010-05-11 04:20:54 +00:00
|
|
|
int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause);
|
|
|
|
int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause);
|
|
|
|
int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc);
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2010-05-19 12:38:50 +00:00
|
|
|
/* Listen for incoming GPRS packets via NS/FR/GRE */
|
2010-05-19 13:09:09 +00:00
|
|
|
int gprs_ns_frgre_listen(struct gprs_ns_inst *nsi);
|
2010-04-30 18:26:32 +00:00
|
|
|
|
2012-06-17 04:25:53 +00:00
|
|
|
struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci);
|
|
|
|
void gprs_nsvc_delete(struct gprs_nsvc *nsvc);
|
|
|
|
struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei);
|
|
|
|
struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci);
|
2010-05-13 09:45:07 +00:00
|
|
|
|
2010-05-14 11:53:08 +00:00
|
|
|
/* Initiate a RESET procedure (including timer start, ...)*/
|
2010-05-23 13:18:01 +00:00
|
|
|
void gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause);
|
2010-05-14 11:53:08 +00:00
|
|
|
|
2010-05-12 15:55:23 +00:00
|
|
|
/* Add NS-specific VTY stuff */
|
|
|
|
int gprs_ns_vty_init(struct gprs_ns_inst *nsi);
|
|
|
|
|
2010-06-14 14:11:40 +00:00
|
|
|
#define NS_ALLOC_SIZE 2048
|
2010-05-19 13:38:10 +00:00
|
|
|
#define NS_ALLOC_HEADROOM 20
|
|
|
|
static inline struct msgb *gprs_ns_msgb_alloc(void)
|
|
|
|
{
|
|
|
|
return msgb_alloc_headroom(NS_ALLOC_SIZE, NS_ALLOC_HEADROOM, "GPRS/NS");
|
|
|
|
}
|
2010-05-19 12:38:50 +00:00
|
|
|
|
2012-06-16 08:40:42 +00:00
|
|
|
enum signal_ns {
|
|
|
|
S_NS_RESET,
|
|
|
|
S_NS_BLOCK,
|
|
|
|
S_NS_UNBLOCK,
|
|
|
|
S_NS_ALIVE_EXP, /* Tns-alive expired more than N times */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ns_signal_data {
|
|
|
|
struct gprs_nsvc *nsvc;
|
|
|
|
uint8_t cause;
|
|
|
|
};
|
|
|
|
|
2012-06-16 09:45:59 +00:00
|
|
|
void gprs_ns_set_log_ss(int ss);
|
|
|
|
|
2011-11-23 14:01:31 +00:00
|
|
|
/*! }@ */
|
|
|
|
|
2010-03-14 07:45:01 +00:00
|
|
|
#endif
|