blob: 02945e16430b9ab5202673814c4a9c8d939873b0 [file] [log] [blame]
Harald Welte9b455bf2010-03-14 15:45:01 +08001#ifndef _GPRS_LLC_H
2#define _GPRS_LLC_H
3
Harald Welteeaa614c2010-05-02 11:26:34 +02004#include <stdint.h>
Harald Welte807a5d82010-06-01 11:53:01 +02005#include <openbsc/gprs_sgsn.h>
Harald Welteeaa614c2010-05-02 11:26:34 +02006
Harald Welte9b455bf2010-03-14 15:45:01 +08007/* Section 4.7 LLC Layer Structure */
8enum gprs_llc_sapi {
9 GPRS_SAPI_GMM = 1,
10 GPRS_SAPI_TOM2 = 2,
11 GPRS_SAPI_SNDCP3 = 3,
12 GPRS_SAPI_SNDCP5 = 5,
13 GPRS_SAPI_SMS = 7,
14 GPRS_SAPI_TOM8 = 8,
15 GPRS_SAPI_SNDCP9 = 9,
16 GPRS_SAPI_SNDCP11 = 11,
17};
18
Harald Welte10997d02010-05-03 12:28:12 +020019/* Section 6.4 Commands and Responses */
20enum gprs_llc_u_cmd {
21 GPRS_LLC_U_DM_RESP = 0x01,
22 GPRS_LLC_U_DISC_CMD = 0x04,
23 GPRS_LLC_U_UA_RESP = 0x06,
24 GPRS_LLC_U_SABM_CMD = 0x07,
25 GPRS_LLC_U_FRMR_RESP = 0x08,
26 GPRS_LLC_U_XID = 0x0b,
27 GPRS_LLC_U_NULL_CMD = 0x00,
28};
Harald Welte9b455bf2010-03-14 15:45:01 +080029
Harald Welte1ae09c72010-05-13 19:22:55 +020030/* TS 04.64 Section 7.1.2 Table 7: LLC layer primitives (GMM/SNDCP/SMS/TOM) */
31/* TS 04.65 Section 5.1.2 Table 2: Service primitives used by SNDCP */
32enum gprs_llc_primitive {
33 /* GMM <-> LLME */
34 LLGMM_ASSIGN_REQ, /* GMM tells us new TLLI: TLLI old, TLLI new, Kc, CiphAlg */
35 LLGMM_RESET_REQ, /* GMM tells us to perform XID negotiation: TLLI */
36 LLGMM_RESET_CNF, /* LLC informs GMM that XID has completed: TLLI */
37 LLGMM_SUSPEND_REQ, /* GMM tells us MS has suspended: TLLI, Page */
38 LLGMM_RESUME_REQ, /* GMM tells us MS has resumed: TLLI */
39 LLGMM_PAGE_IND, /* LLC asks GMM to page MS: TLLI */
40 LLGMM_IOV_REQ, /* GMM tells us to perform XID: TLLI */
41 LLGMM_STATUS_IND, /* LLC informs GMM about error: TLLI, Cause */
42 /* LLE <-> (GMM/SNDCP/SMS/TOM) */
43 LL_RESET_IND, /* TLLI */
44 LL_ESTABLISH_REQ, /* TLLI, XID Req */
45 LL_ESTABLISH_IND, /* TLLI, XID Req, N201-I, N201-U */
46 LL_ESTABLISH_RESP, /* TLLI, XID Negotiated */
47 LL_ESTABLISH_CONF, /* TLLI, XID Neg, N201-i, N201-U */
48 LL_RELEASE_REQ, /* TLLI, Local */
49 LL_RELEASE_IND, /* TLLI, Cause */
50 LL_RELEASE_CONF, /* TLLI */
51 LL_XID_REQ, /* TLLI, XID Requested */
52 LL_XID_IND, /* TLLI, XID Req, N201-I, N201-U */
53 LL_XID_RESP, /* TLLI, XID Negotiated */
54 LL_XID_CONF, /* TLLI, XID Neg, N201-I, N201-U */
55 LL_DATA_REQ, /* TLLI, SN-PDU, Ref, QoS, Radio Prio, Ciph */
56 LL_DATA_IND, /* TLLI, SN-PDU */
57 LL_DATA_CONF, /* TLLI, Ref */
58 LL_UNITDATA_REQ, /* TLLI, SN-PDU, Ref, QoS, Radio Prio, Ciph */
59 LL_UNITDATA_IND, /* TLLI, SN-PDU */
60 LL_STATUS_IND, /* TLLI, Cause */
61};
62
Harald Welte2e918a82010-05-18 12:20:12 +020063/* Section 4.5.2 Logical Link States + Annex C.2 */
Harald Welte807a5d82010-06-01 11:53:01 +020064enum gprs_llc_lle_state {
65 GPRS_LLES_UNASSIGNED = 1, /* No TLLI yet */
66 GPRS_LLES_ASSIGNED_ADM = 2, /* TLLI assigned */
67 GPRS_LLES_LOCAL_EST = 3, /* Local Establishment */
68 GPRS_LLES_REMOTE_EST = 4, /* Remote Establishment */
69 GPRS_LLES_ABM = 5,
70 GPRS_LLES_LOCAL_REL = 6, /* Local Release */
71 GPRS_LLES_TIMER_REC = 7, /* Timer Recovery */
72};
73
74enum gprs_llc_llme_state {
75 GPRS_LLMS_UNASSIGNED = 1, /* No TLLI yet */
76 GPRS_LLMS_ASSIGNED = 2, /* TLLI assigned */
Harald Welte2e918a82010-05-18 12:20:12 +020077};
78
Harald Welte1d9d9442010-06-03 07:11:04 +020079/* Section 8.9.9 LLC layer parameter default values */
80struct gprs_llc_params {
81 uint16_t iov_i_exp;
82 uint16_t t200_201;
83 uint16_t n200;
84 uint16_t n201_u;
85 uint16_t n201_i;
86 uint16_t mD;
87 uint16_t mU;
88 uint16_t kD;
89 uint16_t kU;
90};
91
Harald Welte2e918a82010-05-18 12:20:12 +020092/* Section 4.7.1: Logical Link Entity: One per DLCI (TLLI + SAPI) */
93struct gprs_llc_lle {
94 struct llist_head list;
95
Harald Welte807a5d82010-06-01 11:53:01 +020096 uint32_t sapi;
97
98 struct gprs_llc_llme *llme;
99
100 enum gprs_llc_lle_state state;
101
Harald Welte2e918a82010-05-18 12:20:12 +0200102 struct timer_list t200;
103 struct timer_list t201; /* wait for acknowledgement */
104
Harald Welte6bdee6a2010-05-30 21:51:58 +0200105 uint16_t v_sent;
106 uint16_t v_ack;
107 uint16_t v_recv;
108
109 uint16_t vu_send;
110 uint16_t vu_recv;
Harald Welte2e918a82010-05-18 12:20:12 +0200111
Harald Welted07b4f92010-06-30 23:07:59 +0200112 /* Overflow Counter for ABM */
113 uint32_t oc_i_send;
114 uint32_t oc_i_recv;
115
116 /* Overflow Counter for unconfirmed transfer */
117 uint32_t oc_ui_send;
118 uint32_t oc_ui_recv;
119
Harald Welte2e918a82010-05-18 12:20:12 +0200120 unsigned int retrans_ctr;
Harald Welte1d9d9442010-06-03 07:11:04 +0200121
122 struct gprs_llc_params params;
Harald Welte807a5d82010-06-01 11:53:01 +0200123};
124
125#define NUM_SAPIS 16
126
127struct gprs_llc_llme {
128 struct llist_head list;
129
130 enum gprs_llc_llme_state state;
131
132 uint32_t tlli;
133 uint32_t old_tlli;
Harald Welte2e918a82010-05-18 12:20:12 +0200134
Harald Welted07b4f92010-06-30 23:07:59 +0200135 /* Crypto parameters */
136 enum gprs_ciph_algo algo;
137 uint8_t kc[8];
138
Harald Welte2e918a82010-05-18 12:20:12 +0200139 /* over which BSSGP BTS ctx do we need to transmit */
140 uint16_t bvci;
141 uint16_t nsei;
Harald Welte807a5d82010-06-01 11:53:01 +0200142 struct gprs_llc_lle lle[NUM_SAPIS];
Harald Welte2e918a82010-05-18 12:20:12 +0200143};
144
Harald Welte807a5d82010-06-01 11:53:01 +0200145extern struct llist_head gprs_llc_llmes;
Harald Welte2e918a82010-05-18 12:20:12 +0200146
Harald Welte1ae09c72010-05-13 19:22:55 +0200147/* BSSGP-UL-UNITDATA.ind */
Harald Welte9b455bf2010-03-14 15:45:01 +0800148int gprs_llc_rcvmsg(struct msgb *msg, struct tlv_parsed *tv);
Harald Welte1ae09c72010-05-13 19:22:55 +0200149
150/* LL-UNITDATA.req */
Harald Welte56a01452010-05-31 22:12:30 +0200151int gprs_llc_tx_ui(struct msgb *msg, uint8_t sapi, int command,
152 void *mmctx);
Harald Welte9b455bf2010-03-14 15:45:01 +0800153
Harald Welte807a5d82010-06-01 11:53:01 +0200154/* 04.64 Chapter 7.2.1.1 LLGMM-ASSIGN */
155int gprs_llgmm_assign(struct gprs_llc_llme *llme,
156 uint32_t old_tlli, uint32_t new_tlli,
157 enum gprs_ciph_algo alg, const uint8_t *kc);
158
Harald Welte496aee42010-06-30 19:59:55 +0200159int gprs_llc_init(const char *cipher_plugin_path);
Harald Welte2e918a82010-05-18 12:20:12 +0200160int gprs_llc_vty_init(void);
161
Harald Welte9b455bf2010-03-14 15:45:01 +0800162#endif