Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | #ifndef _GPRS_BSSGP_H |
| 2 | #define _GPRS_BSSGP_H |
| 3 | |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 4 | #include <stdint.h> |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 5 | #include <osmocom/core/timer.h> |
| 6 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 7 | |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 8 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 9 | #include <osmocom/gsm/prim.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 10 | |
Harald Welte | 8648e49 | 2012-06-17 13:12:51 +0800 | [diff] [blame] | 11 | #include <osmocom/gprs/protocol/gsm_08_18.h> |
| 12 | |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 13 | /* gprs_bssgp_util.c */ |
| 14 | extern struct gprs_ns_inst *bssgp_nsi; |
| 15 | struct msgb *bssgp_msgb_alloc(void); |
| 16 | const char *bssgp_cause_str(enum gprs_bssgp_cause cause); |
| 17 | /* Transmit a simple response such as BLOCK/UNBLOCK/RESET ACK/NACK */ |
| 18 | int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei, |
| 19 | uint16_t bvci, uint16_t ns_bvci); |
| 20 | /* Chapter 10.4.14: Status */ |
| 21 | int bssgp_tx_status(uint8_t cause, uint16_t *bvci, struct msgb *orig_msg); |
| 22 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 23 | enum bssgp_prim { |
| 24 | PRIM_BSSGP_DL_UD, |
| 25 | PRIM_BSSGP_UL_UD, |
| 26 | PRIM_BSSGP_PTM_UD, |
| 27 | |
| 28 | PRIM_BSSGP_GMM_SUSPEND, |
| 29 | PRIM_BSSGP_GMM_RESUME, |
| 30 | PRIM_BSSGP_GMM_PAGING, |
| 31 | |
| 32 | PRIM_NM_FLUSH_LL, |
| 33 | PRIM_NM_LLC_DISCARDED, |
| 34 | PRIM_NM_BVC_RESET, |
| 35 | PRIM_NM_BVC_BLOCK, |
| 36 | PRIM_NM_BVC_UNBLOCK, |
| 37 | }; |
| 38 | |
| 39 | struct osmo_bssgp_prim { |
| 40 | struct osmo_prim_hdr oph; |
| 41 | |
| 42 | /* common fields */ |
| 43 | uint16_t nsei; |
| 44 | uint16_t bvci; |
| 45 | uint32_t tlli; |
| 46 | struct tlv_parsed *tp; |
| 47 | struct gprs_ra_id *ra_id; |
| 48 | |
| 49 | /* specific fields */ |
| 50 | union { |
| 51 | struct { |
Holger Hans Peter Freyther | d296f42 | 2012-08-03 09:59:20 +0200 | [diff] [blame] | 52 | uint8_t suspend_ref; |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 53 | } resume; |
| 54 | } u; |
| 55 | }; |
| 56 | |
Harald Welte | af08678 | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 57 | /* gprs_bssgp.c */ |
| 58 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 59 | /*! \brief BSSGP flow control (SGSN side) According to Section 8.2 */ |
| 60 | struct bssgp_flow_control { |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 61 | uint32_t bucket_size_max; /*!< maximum size of the bucket (octets) */ |
| 62 | uint32_t bucket_leak_rate; /*!< leak rate of the bucket (octets/sec) */ |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 63 | |
| 64 | uint32_t bucket_counter; /*!< number of tokens in the bucket */ |
| 65 | struct timeval time_last_pdu; /*!< timestamp of last PDU sent */ |
| 66 | |
| 67 | /* the built-in queue */ |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 68 | uint32_t max_queue_depth; /*!< how many packets to queue (mgs) */ |
| 69 | uint32_t queue_depth; /*!< current length of queue (msgs) */ |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 70 | struct llist_head queue; /*!< linked list of msgb's */ |
| 71 | struct osmo_timer_list timer; /*!< timer-based dequeueing */ |
| 72 | |
| 73 | /*! callback to be called at output of flow control */ |
| 74 | int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, |
| 75 | uint32_t llc_pdu_len, void *priv); |
| 76 | }; |
| 77 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 78 | #define BVC_S_BLOCKED 0x0001 |
| 79 | |
| 80 | /* The per-BTS context that we keep on the SGSN side of the BSSGP link */ |
| 81 | struct bssgp_bvc_ctx { |
| 82 | struct llist_head list; |
| 83 | |
Harald Welte | eb3ccf6 | 2011-11-25 08:15:42 +0100 | [diff] [blame] | 84 | struct gprs_ra_id ra_id; /*!< parsed RA ID of the remote BTS */ |
| 85 | uint16_t cell_id; /*!< Cell ID of the remote BTS */ |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 86 | |
| 87 | /* NSEI and BVCI of underlying Gb link. Together they |
| 88 | * uniquely identify a link to a BTS (5.4.4) */ |
| 89 | uint16_t bvci; |
| 90 | uint16_t nsei; |
| 91 | |
| 92 | uint32_t state; |
| 93 | |
| 94 | struct rate_ctr_group *ctrg; |
| 95 | |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 96 | struct bssgp_flow_control *fc; |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 97 | /*! default maximum size of per-MS bucket in octets */ |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 98 | uint32_t bmax_default_ms; |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 99 | /*! default bucket leak rate of per-MS bucket in octests/s */ |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 100 | uint32_t r_default_ms; |
| 101 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 102 | /* we might want to add this as a shortcut later, avoiding the NSVC |
| 103 | * lookup for every packet, similar to a routing cache */ |
| 104 | //struct gprs_nsvc *nsvc; |
| 105 | }; |
| 106 | extern struct llist_head bssgp_bvc_ctxts; |
| 107 | /* Find a BTS Context based on parsed RA ID and Cell ID */ |
| 108 | struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid); |
| 109 | /* Find a BTS context based on BVCI+NSEI tuple */ |
| 110 | struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei); |
| 111 | |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 112 | #define BVC_F_BLOCKED 0x0001 |
| 113 | |
| 114 | enum bssgp_ctr { |
| 115 | BSSGP_CTR_PKTS_IN, |
| 116 | BSSGP_CTR_PKTS_OUT, |
| 117 | BSSGP_CTR_BYTES_IN, |
| 118 | BSSGP_CTR_BYTES_OUT, |
| 119 | BSSGP_CTR_BLOCKED, |
| 120 | BSSGP_CTR_DISCARDED, |
| 121 | }; |
| 122 | |
| 123 | |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 124 | #include <osmocom/gsm/tlv.h> |
Harald Welte | 605ac5d | 2012-06-16 16:09:52 +0800 | [diff] [blame] | 125 | #include <osmocom/gprs/gprs_msgb.h> |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 126 | |
Harald Welte | 6111234 | 2010-05-13 19:25:59 +0200 | [diff] [blame] | 127 | /* BSSGP-UL-UNITDATA.ind */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 128 | int bssgp_rcvmsg(struct msgb *msg); |
Harald Welte | 6111234 | 2010-05-13 19:25:59 +0200 | [diff] [blame] | 129 | |
| 130 | /* BSSGP-DL-UNITDATA.req */ |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 131 | struct bssgp_lv { |
| 132 | uint16_t len; |
| 133 | uint8_t *v; |
| 134 | }; |
| 135 | /* parameters for BSSGP downlink userdata transmission */ |
| 136 | struct bssgp_dl_ud_par { |
| 137 | uint32_t *tlli; |
| 138 | char *imsi; |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 139 | struct bssgp_flow_control *fc; |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 140 | uint16_t drx_parms; |
| 141 | /* FIXME: priority */ |
| 142 | struct bssgp_lv ms_ra_cap; |
| 143 | uint8_t qos_profile[3]; |
| 144 | }; |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 145 | int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, |
| 146 | struct bssgp_dl_ud_par *dup); |
Harald Welte | 6111234 | 2010-05-13 19:25:59 +0200 | [diff] [blame] | 147 | |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 148 | uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 149 | int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, |
| 150 | uint16_t cid); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 151 | |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 152 | /* Wrapper around TLV parser to parse BSSGP IEs */ |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 153 | static inline int bssgp_tlv_parse(struct tlv_parsed *tp, uint8_t *buf, int len) |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 154 | { |
| 155 | return tlv_parse(tp, &tvlv_att_def, buf, len, 0, 0); |
| 156 | } |
| 157 | |
Harald Welte | eb3ccf6 | 2011-11-25 08:15:42 +0100 | [diff] [blame] | 158 | /*! \brief BSSGP Paging mode */ |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 159 | enum bssgp_paging_mode { |
| 160 | BSSGP_PAGING_PS, |
| 161 | BSSGP_PAGING_CS, |
| 162 | }; |
| 163 | |
Harald Welte | eb3ccf6 | 2011-11-25 08:15:42 +0100 | [diff] [blame] | 164 | /*! \brief BSSGP Paging scope */ |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 165 | enum bssgp_paging_scope { |
Harald Welte | eb3ccf6 | 2011-11-25 08:15:42 +0100 | [diff] [blame] | 166 | BSSGP_PAGING_BSS_AREA, /*!< all cells in BSS */ |
| 167 | BSSGP_PAGING_LOCATION_AREA, /*!< all cells in LA */ |
| 168 | BSSGP_PAGING_ROUTEING_AREA, /*!< all cells in RA */ |
| 169 | BSSGP_PAGING_BVCI, /*!< one cell */ |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 170 | }; |
| 171 | |
Harald Welte | eb3ccf6 | 2011-11-25 08:15:42 +0100 | [diff] [blame] | 172 | /*! \brief BSSGP paging information */ |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 173 | struct bssgp_paging_info { |
Harald Welte | eb3ccf6 | 2011-11-25 08:15:42 +0100 | [diff] [blame] | 174 | enum bssgp_paging_mode mode; /*!< CS or PS paging */ |
| 175 | enum bssgp_paging_scope scope; /*!< bssgp_paging_scope */ |
| 176 | struct gprs_ra_id raid; /*!< RA Identifier */ |
| 177 | uint16_t bvci; /*!< BVCI */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 178 | char *imsi; /*!< IMSI, if any */ |
Harald Welte | eb3ccf6 | 2011-11-25 08:15:42 +0100 | [diff] [blame] | 179 | uint32_t *ptmsi; /*!< P-TMSI, if any */ |
| 180 | uint16_t drx_params; /*!< DRX parameters */ |
| 181 | uint8_t qos[3]; /*!< QoS parameters */ |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | /* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 185 | int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, |
| 186 | struct bssgp_paging_info *pinfo); |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 187 | |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 188 | void bssgp_fc_init(struct bssgp_flow_control *fc, |
| 189 | uint32_t bucket_size_max, uint32_t bucket_leak_rate, |
| 190 | uint32_t max_queue_depth, |
| 191 | int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, |
| 192 | uint32_t llc_pdu_len, void *priv)); |
| 193 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 194 | /* input function of the flow control implementation, called first |
| 195 | * for the MM flow control, and then as the MM flow control output |
| 196 | * callback in order to perform BVC flow control */ |
| 197 | int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, |
| 198 | uint32_t llc_pdu_len, void *priv); |
| 199 | |
| 200 | /* Initialize the Flow Control parameters for a new MS according to |
| 201 | * default values for the BVC specified by BVCI and NSEI */ |
| 202 | int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci, |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 203 | uint16_t nsei, uint32_t max_queue_depth); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 204 | |
Harald Welte | fdc7388 | 2010-05-18 08:02:36 +0200 | [diff] [blame] | 205 | /* gprs_bssgp_vty.c */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 206 | int bssgp_vty_init(void); |
| 207 | void bssgp_set_log_ss(int ss); |
Harald Welte | fdc7388 | 2010-05-18 08:02:36 +0200 | [diff] [blame] | 208 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 209 | int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx); |
| 210 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 211 | #endif /* _GPRS_BSSGP_H */ |