blob: ab32a8308f41352e8382fe21e168f4fb0b1aee98 [file] [log] [blame]
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +02001/* (C) 2009,2010 by Holger Hans Peter Freyther <zecke@selfish.org>
2 * (C) 2009,2010 by On-Waves
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <osmocore/gsm0808.h>
22#include <osmocore/protocol/gsm_08_08.h>
23#include <osmocore/gsm48.h>
24
25#include <arpa/inet.h>
26
27#define BSSMAP_MSG_SIZE 512
28#define BSSMAP_MSG_HEADROOM 128
29
30struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc, uint16_t cc, int lac, int _ci)
31{
32 uint8_t *data;
33 uint16_t *ci;
34 struct msgb* msg;
35 struct gsm48_loc_area_id *lai;
36
37 msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
38 "bssmap cmpl l3");
39 if (!msg)
40 return NULL;
41
42 /* create the bssmap header */
43 msg->l3h = msgb_put(msg, 2);
44 msg->l3h[0] = 0x0;
45
46 /* create layer 3 header */
47 data = msgb_put(msg, 1);
48 data[0] = BSS_MAP_MSG_COMPLETE_LAYER_3;
49
50 /* create the cell header */
51 data = msgb_put(msg, 3);
52 data[0] = GSM0808_IE_CELL_IDENTIFIER;
53 data[1] = 1 + sizeof(*lai) + 2;
54 data[2] = CELL_IDENT_WHOLE_GLOBAL;
55
56 lai = (struct gsm48_loc_area_id *) msgb_put(msg, sizeof(*lai));
57 gsm48_generate_lai(lai, cc, nc, lac);
58
59 ci = (uint16_t *) msgb_put(msg, 2);
60 *ci = htons(_ci);
61
62 /* copy the layer3 data */
63 data = msgb_put(msg, msgb_l3len(msg_l3) + 2);
64 data[0] = GSM0808_IE_LAYER_3_INFORMATION;
65 data[1] = msgb_l3len(msg_l3);
66 memcpy(&data[2], msg_l3->l3h, data[1]);
67
68 /* update the size */
69 msg->l3h[1] = msgb_l3len(msg) - 2;
70
71 return msg;
72}
73
74struct msgb *gsm0808_create_reset(void)
75{
76 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
77 "bssmap: reset");
78 if (!msg)
79 return NULL;
80
81 msg->l3h = msgb_put(msg, 6);
82 msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
83 msg->l3h[1] = 0x04;
84 msg->l3h[2] = 0x30;
85 msg->l3h[3] = 0x04;
86 msg->l3h[4] = 0x01;
87 msg->l3h[5] = 0x20;
88 return msg;
89}
90
91struct msgb *gsm0808_create_clear_complete(void)
92{
93 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
94 "bssmap: clear complete");
95 if (!msg)
96 return NULL;
97
98 msg->l3h = msgb_put(msg, 3);
99 msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
100 msg->l3h[1] = 1;
101 msg->l3h[2] = BSS_MAP_MSG_CLEAR_COMPLETE;
102
103 return msg;
104}
105
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +0200106struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id)
107{
108 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
109 "cipher-complete");
110 if (!msg)
111 return NULL;
112
113 /* send response with BSS override for A5/1... cheating */
114 msg->l3h = msgb_put(msg, 3);
115 msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
116 msg->l3h[1] = 0xff;
117 msg->l3h[2] = BSS_MAP_MSG_CIPHER_MODE_COMPLETE;
118
119 /* include layer3 in case we have at least two octets */
120 if (layer3 && msgb_l3len(layer3) > 2) {
121 msg->l4h = msgb_put(msg, msgb_l3len(layer3) + 2);
122 msg->l4h[0] = GSM0808_IE_LAYER_3_MESSAGE_CONTENTS;
123 msg->l4h[1] = msgb_l3len(layer3);
124 memcpy(&msg->l4h[2], layer3->l3h, msgb_l3len(layer3));
125 }
126
127 /* and the optional BSS message */
128 msg->l4h = msgb_put(msg, 2);
129 msg->l4h[0] = GSM0808_IE_CHOSEN_ENCR_ALG;
130 msg->l4h[1] = alg_id;
131
132 /* update the size */
133 msg->l3h[1] = msgb_l3len(msg) - 2;
134 return msg;
135}
136
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200137struct msgb *gsm0808_create_cipher_reject(uint8_t cause)
138{
139 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
140 "bssmap: clear complete");
141 if (!msg)
142 return NULL;
143
144 msg->l3h = msgb_put(msg, 3);
145 msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
146 msg->l3h[1] = 2;
147 msg->l3h[2] = BSS_MAP_MSG_CIPHER_MODE_REJECT;
148 msg->l3h[3] = cause;
149
150 return msg;
151}
152
153struct msgb *gsm0808_create_classmark_update(const uint8_t *classmark_data, u_int8_t length)
154{
155 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
156 "classmark-update");
157 if (!msg)
158 return NULL;
159
160 msg->l3h = msgb_put(msg, 3);
161 msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
162 msg->l3h[1] = 0xff;
163 msg->l3h[2] = BSS_MAP_MSG_CLASSMARK_UPDATE;
164
165 msg->l4h = msgb_put(msg, length);
166 memcpy(msg->l4h, classmark_data, length);
167
168 /* update the size */
169 msg->l3h[1] = msgb_l3len(msg) - 2;
170 return msg;
171}
172
173struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
174{
175 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
176 "bssmap: sapi 'n' reject");
177 if (!msg)
178 return NULL;
179
180 msg->l3h = msgb_put(msg, 5);
181 msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
182 msg->l3h[1] = 3;
183 msg->l3h[2] = BSS_MAP_MSG_SAPI_N_REJECT;
184 msg->l3h[3] = link_id;
185 msg->l3h[4] = GSM0808_CAUSE_BSS_NOT_EQUIPPED;
186
187 return msg;
188}
189
190struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause)
191{
192 uint8_t *data;
193 struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
194 "bssmap: ass fail");
195 if (!msg)
196 return NULL;
197
198 msg->l3h = msgb_put(msg, 6);
199 msg->l3h[0] = BSSAP_MSG_BSS_MANAGEMENT;
200 msg->l3h[1] = 0xff;
201 msg->l3h[2] = BSS_MAP_MSG_ASSIGMENT_FAILURE;
202 msg->l3h[3] = GSM0808_IE_CAUSE;
203 msg->l3h[4] = 1;
204 msg->l3h[5] = cause;
205
206 /* RR cause 3.2.2.22 */
207 if (rr_cause) {
208 data = msgb_put(msg, 2);
209 data[0] = GSM0808_IE_RR_CAUSE;
210 data[1] = *rr_cause;
211 }
212
213 /* Circuit pool 3.22.45 */
214 /* Circuit pool list 3.2.2.46 */
215
216 /* update the size */
217 msg->l3h[1] = msgb_l3len(msg) - 2;
218 return msg;
219}
Holger Hans Peter Freyther7daa01c2010-04-17 05:14:36 +0200220
221static const struct tlv_definition bss_att_tlvdef = {
222 .def = {
223 [GSM0808_IE_IMSI] = { TLV_TYPE_TLV },
224 [GSM0808_IE_TMSI] = { TLV_TYPE_TLV },
225 [GSM0808_IE_CELL_IDENTIFIER_LIST] = { TLV_TYPE_TLV },
226 [GSM0808_IE_CHANNEL_NEEDED] = { TLV_TYPE_TV },
227 [GSM0808_IE_EMLPP_PRIORITY] = { TLV_TYPE_TV },
228 [GSM0808_IE_CHANNEL_TYPE] = { TLV_TYPE_TLV },
229 [GSM0808_IE_PRIORITY] = { TLV_TYPE_TLV },
230 [GSM0808_IE_CIRCUIT_IDENTITY_CODE] = { TLV_TYPE_TV },
231 [GSM0808_IE_DOWNLINK_DTX_FLAG] = { TLV_TYPE_TV },
232 [GSM0808_IE_INTERFERENCE_BAND_TO_USE] = { TLV_TYPE_TV },
233 [GSM0808_IE_CLASSMARK_INFORMATION_T2] = { TLV_TYPE_TLV },
234 [GSM0808_IE_GROUP_CALL_REFERENCE] = { TLV_TYPE_TLV },
235 [GSM0808_IE_TALKER_FLAG] = { TLV_TYPE_T },
236 [GSM0808_IE_CONFIG_EVO_INDI] = { TLV_TYPE_TV },
237 [GSM0808_IE_LSA_ACCESS_CTRL_SUPPR] = { TLV_TYPE_TV },
238 [GSM0808_IE_SERVICE_HANDOVER] = { TLV_TYPE_TV},
239 [GSM0808_IE_ENCRYPTION_INFORMATION] = { TLV_TYPE_TLV },
240 [GSM0808_IE_CIPHER_RESPONSE_MODE] = { TLV_TYPE_TV },
241 },
242};
243
244const struct tlv_definition *gsm0808_att_tlvdef()
245{
246 return &bss_att_tlvdef;
247}