blob: 1df5174a1daf92b53849b475b4651b0af3bae5e0 [file] [log] [blame]
Harald Weltedd2a34f2009-10-26 20:42:55 +01001/* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface
Harald Welte03115042009-10-16 08:32:58 +02002 * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */
3
4/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther4e1c7f12010-07-25 18:08:53 +08005 * (C) 2008, 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Harald Welte03115042009-10-16 08:32:58 +02006 * (C) 2009 by Mike Haben <michael.haben@btinternet.com>
7 *
8 * All Rights Reserved
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 */
25
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <errno.h>
31
Harald Welte03115042009-10-16 08:32:58 +020032#include <openbsc/debug.h>
33#include <openbsc/gsm_data.h>
Harald Welte03115042009-10-16 08:32:58 +020034#include <openbsc/gsm_04_08.h>
35#include <openbsc/gsm_04_80.h>
Holger Hans Peter Freyther5bc4d1d2010-06-15 13:57:40 +080036#include <openbsc/bsc_api.h>
Harald Welte03115042009-10-16 08:32:58 +020037
Holger Hans Peter Freythera101b4b2010-09-30 18:48:28 +080038#include <osmocore/gsm_utils.h>
39#include <osmocore/msgb.h>
40#include <osmocore/tlv.h>
41
Harald Welte03115042009-10-16 08:32:58 +020042/* Forward declarations */
Mike Haben775a1a42009-10-22 09:56:44 +020043static int parse_ussd(u_int8_t *ussd, struct ussd_request *req);
Harald Welte36ec2be2009-10-26 20:42:07 +010044static int parse_ussd_info_elements(u_int8_t *ussd_ie,
Mike Haben775a1a42009-10-22 09:56:44 +020045 struct ussd_request *req);
Harald Welte36ec2be2009-10-26 20:42:07 +010046static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length,
Mike Haben775a1a42009-10-22 09:56:44 +020047 struct ussd_request *req);
Harald Welte36ec2be2009-10-26 20:42:07 +010048static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length,
Mike Haben775a1a42009-10-22 09:56:44 +020049 struct ussd_request *req);
Harald Welte36ec2be2009-10-26 20:42:07 +010050static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length,
Mike Haben775a1a42009-10-22 09:56:44 +020051 struct ussd_request *req);
Harald Welte03115042009-10-16 08:32:58 +020052
53static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, u_int8_t tag)
54{
Holger Hans Peter Freytherbb2418a2010-07-26 19:08:59 +080055 uint8_t *data = msgb_push(msgb, 2);
56
57 data[0] = tag;
Holger Hans Peter Freyther0c465ef2010-07-27 01:25:59 +080058 data[1] = msgb->len - 2;
Holger Hans Peter Freytherbb2418a2010-07-26 19:08:59 +080059 return data;
Harald Welte03115042009-10-16 08:32:58 +020060}
61
Harald Weltefb957252009-10-16 08:41:51 +020062static inline unsigned char *msgb_push_TLV1(struct msgb *msgb, u_int8_t tag,
63 u_int8_t value)
Harald Welte03115042009-10-16 08:32:58 +020064{
Holger Hans Peter Freytherbb2418a2010-07-26 19:08:59 +080065 uint8_t *data = msgb_push(msgb, 3);
66
67 data[0] = tag;
68 data[1] = 1;
69 data[2] = value;
70 return data;
Harald Welte03115042009-10-16 08:32:58 +020071}
72
73
Mike Haben775a1a42009-10-22 09:56:44 +020074/* Decode a mobile-originated USSD-request message */
Mike Habenc0c50792009-10-26 20:36:34 +010075int gsm0480_decode_ussd_request(const struct msgb *msg, struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +020076{
77 int rc = 0;
Harald Weltefb957252009-10-16 08:41:51 +020078 u_int8_t *parse_ptr = msgb_l3(msg);
Harald Welte03115042009-10-16 08:32:58 +020079
Harald Welte03115042009-10-16 08:32:58 +020080 if ((*parse_ptr & 0x0F) == GSM48_PDISC_NC_SS) {
Mike Haben775a1a42009-10-22 09:56:44 +020081 req->transaction_id = *parse_ptr & 0x70;
82 rc = parse_ussd(parse_ptr+1, req);
Harald Welte03115042009-10-16 08:32:58 +020083 }
84
85 if (!rc)
Harald Welte36ec2be2009-10-26 20:42:07 +010086 DEBUGP(DMM, "Error occurred while parsing received USSD!\n");
Harald Welte03115042009-10-16 08:32:58 +020087
Mike Haben775a1a42009-10-22 09:56:44 +020088 return rc;
Harald Welte03115042009-10-16 08:32:58 +020089}
90
Mike Haben775a1a42009-10-22 09:56:44 +020091static int parse_ussd(u_int8_t *ussd, struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +020092{
93 int rc = 1;
94 u_int8_t msg_type = ussd[0] & 0xBF; /* message-type - section 3.4 */
95
Harald Weltefb957252009-10-16 08:41:51 +020096 switch (msg_type) {
Harald Welte03115042009-10-16 08:32:58 +020097 case GSM0480_MTYPE_RELEASE_COMPLETE:
Harald Weltefb957252009-10-16 08:41:51 +020098 DEBUGP(DMM, "USS Release Complete\n");
99 /* could also parse out the optional Cause/Facility data */
Mike Haben775a1a42009-10-22 09:56:44 +0200100 req->text[0] = 0xFF;
Harald Welte03115042009-10-16 08:32:58 +0200101 break;
102 case GSM0480_MTYPE_REGISTER:
103 case GSM0480_MTYPE_FACILITY:
Mike Haben775a1a42009-10-22 09:56:44 +0200104 rc &= parse_ussd_info_elements(ussd+1, req);
Harald Welte03115042009-10-16 08:32:58 +0200105 break;
106 default:
107 fprintf(stderr, "Unknown GSM 04.80 message-type field 0x%02x\n",
108 ussd[0]);
109 rc = 0;
110 break;
111 }
112
113 return rc;
114}
115
Mike Haben775a1a42009-10-22 09:56:44 +0200116static int parse_ussd_info_elements(u_int8_t *ussd_ie, struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +0200117{
Holger Hans Peter Freyther73944302010-07-23 19:35:54 +0800118 int rc = -1;
Harald Weltefb957252009-10-16 08:41:51 +0200119 /* Information Element Identifier - table 3.2 & GSM 04.08 section 10.5 */
120 u_int8_t iei = ussd_ie[0];
Harald Welte36ec2be2009-10-26 20:42:07 +0100121 u_int8_t iei_length = ussd_ie[1];
Harald Weltefb957252009-10-16 08:41:51 +0200122
123 switch (iei) {
Harald Welte03115042009-10-16 08:32:58 +0200124 case GSM48_IE_CAUSE:
125 break;
126 case GSM0480_IE_FACILITY:
Mike Haben775a1a42009-10-22 09:56:44 +0200127 rc = parse_facility_ie(ussd_ie+2, iei_length, req);
Harald Welte03115042009-10-16 08:32:58 +0200128 break;
129 case GSM0480_IE_SS_VERSION:
130 break;
131 default:
Harald Weltefb957252009-10-16 08:41:51 +0200132 fprintf(stderr, "Unhandled GSM 04.08 or 04.80 IEI 0x%02x\n",
Harald Welte03115042009-10-16 08:32:58 +0200133 iei);
134 rc = 0;
135 break;
136 }
137
138 return rc;
139}
140
Harald Welte36ec2be2009-10-26 20:42:07 +0100141static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length,
Mike Haben775a1a42009-10-22 09:56:44 +0200142 struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +0200143{
144 int rc = 1;
145 u_int8_t offset = 0;
146
147 do {
Harald Weltefb957252009-10-16 08:41:51 +0200148 /* Component Type tag - table 3.7 */
149 u_int8_t component_type = facility_ie[offset];
Harald Welte03115042009-10-16 08:32:58 +0200150 u_int8_t component_length = facility_ie[offset+1];
Harald Weltefb957252009-10-16 08:41:51 +0200151
152 switch (component_type) {
Harald Welte03115042009-10-16 08:32:58 +0200153 case GSM0480_CTYPE_INVOKE:
Harald Welte36ec2be2009-10-26 20:42:07 +0100154 rc &= parse_ss_invoke(facility_ie+2,
155 component_length,
Mike Haben775a1a42009-10-22 09:56:44 +0200156 req);
Harald Welte03115042009-10-16 08:32:58 +0200157 break;
158 case GSM0480_CTYPE_RETURN_RESULT:
159 break;
160 case GSM0480_CTYPE_RETURN_ERROR:
161 break;
162 case GSM0480_CTYPE_REJECT:
163 break;
164 default:
Harald Weltefb957252009-10-16 08:41:51 +0200165 fprintf(stderr, "Unknown GSM 04.80 Facility "
166 "Component Type 0x%02x\n", component_type);
Harald Welte03115042009-10-16 08:32:58 +0200167 rc = 0;
168 break;
169 }
170 offset += (component_length+2);
Harald Weltefb957252009-10-16 08:41:51 +0200171 } while (offset < length);
Harald Welte03115042009-10-16 08:32:58 +0200172
173 return rc;
174}
175
176/* Parse an Invoke component - see table 3.3 */
Harald Welte36ec2be2009-10-26 20:42:07 +0100177static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length,
Mike Haben775a1a42009-10-22 09:56:44 +0200178 struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +0200179{
180 int rc = 1;
Harald Weltefb957252009-10-16 08:41:51 +0200181 u_int8_t offset;
182
183 /* mandatory part */
184 if (invoke_data[0] != GSM0480_COMPIDTAG_INVOKE_ID) {
185 fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag "
186 "0x%02x (expecting Invoke ID tag)\n", invoke_data[0]);
Harald Welte03115042009-10-16 08:32:58 +0200187 }
Harald Weltefb957252009-10-16 08:41:51 +0200188
189 offset = invoke_data[1] + 2;
Mike Haben775a1a42009-10-22 09:56:44 +0200190 req->invoke_id = invoke_data[2];
Harald Welte03115042009-10-16 08:32:58 +0200191
Harald Weltefb957252009-10-16 08:41:51 +0200192 /* optional part */
193 if (invoke_data[offset] == GSM0480_COMPIDTAG_LINKED_ID)
Harald Welte03115042009-10-16 08:32:58 +0200194 offset += invoke_data[offset+1] + 2; /* skip over it */
Harald Weltefb957252009-10-16 08:41:51 +0200195
196 /* mandatory part */
197 if (invoke_data[offset] == GSM0480_OPERATION_CODE) {
Harald Welte03115042009-10-16 08:32:58 +0200198 u_int8_t operation_code = invoke_data[offset+2];
Harald Weltefb957252009-10-16 08:41:51 +0200199 switch (operation_code) {
Harald Welte03115042009-10-16 08:32:58 +0200200 case GSM0480_OP_CODE_PROCESS_USS_REQ:
Harald Weltefb957252009-10-16 08:41:51 +0200201 rc = parse_process_uss_req(invoke_data + offset + 3,
Mike Haben775a1a42009-10-22 09:56:44 +0200202 length - offset - 3,
203 req);
Harald Welte03115042009-10-16 08:32:58 +0200204 break;
205 default:
Harald Weltefb957252009-10-16 08:41:51 +0200206 fprintf(stderr, "GSM 04.80 operation code 0x%02x "
207 "is not yet handled\n", operation_code);
Harald Welte03115042009-10-16 08:32:58 +0200208 rc = 0;
209 break;
210 }
211 } else {
Harald Weltefb957252009-10-16 08:41:51 +0200212 fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag 0x%02x "
213 "(expecting Operation Code tag)\n",
Harald Welte03115042009-10-16 08:32:58 +0200214 invoke_data[0]);
215 rc = 0;
216 }
217
218 return rc;
219}
220
221/* Parse the parameters of a Process UnstructuredSS Request */
Harald Welte36ec2be2009-10-26 20:42:07 +0100222static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length,
Mike Haben775a1a42009-10-22 09:56:44 +0200223 struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +0200224{
Mike Haben775a1a42009-10-22 09:56:44 +0200225 int rc = 0;
Harald Welte03115042009-10-16 08:32:58 +0200226 int num_chars;
227 u_int8_t dcs;
228
Harald Welte03115042009-10-16 08:32:58 +0200229 if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) {
230 if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) {
231 dcs = uss_req_data[4];
Harald Weltefb957252009-10-16 08:41:51 +0200232 if ((dcs == 0x0F) &&
233 (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) {
Harald Welte03115042009-10-16 08:32:58 +0200234 num_chars = (uss_req_data[6] * 8) / 7;
Mike Habenc0c50792009-10-26 20:36:34 +0100235 /* Prevent a mobile-originated buffer-overrun! */
236 if (num_chars > MAX_LEN_USSD_STRING)
237 num_chars = MAX_LEN_USSD_STRING;
Mike Haben775a1a42009-10-22 09:56:44 +0200238 gsm_7bit_decode(req->text,
Harald Weltefb957252009-10-16 08:41:51 +0200239 &(uss_req_data[7]), num_chars);
Mike Haben775a1a42009-10-22 09:56:44 +0200240 /* append null-terminator */
Holger Hans Peter Freyther71135142010-03-29 08:47:44 +0200241 req->text[num_chars+1] = 0;
Mike Haben775a1a42009-10-22 09:56:44 +0200242 rc = 1;
Harald Welte03115042009-10-16 08:32:58 +0200243 }
244 }
Mike Haben775a1a42009-10-22 09:56:44 +0200245 }
Harald Welte03115042009-10-16 08:32:58 +0200246 return rc;
247}
248
Holger Hans Peter Freyther4e1c7f12010-07-25 18:08:53 +0800249struct msgb *gsm0480_create_notifySS(const char *text)
250{
251 struct msgb *msg;
252 uint8_t *data, *tmp_len;
253 uint8_t *seq_len_ptr, *cal_len_ptr, *opt_len_ptr, *nam_len_ptr;
254 int len;
255
256 len = strlen(text);
257 if (len < 1 || len > 160)
258 return NULL;
259
260 msg = gsm48_msgb_alloc();
261 if (!msg)
262 return NULL;
263
264 msgb_put_u8(msg, GSM_0480_SEQUENCE_TAG);
265 seq_len_ptr = msgb_put(msg, 1);
266
Holger Hans Peter Freyther67daa992010-07-27 04:05:29 +0800267 /* ss_code for CNAP { */
268 msgb_put_u8(msg, 0x81);
269 msgb_put_u8(msg, 1);
270 msgb_put_u8(msg, 0x19);
271 /* } ss_code */
272
Holger Hans Peter Freyther4e1c7f12010-07-25 18:08:53 +0800273
274 /* nameIndicator { */
275 msgb_put_u8(msg, 0xB4);
276 nam_len_ptr = msgb_put(msg, 1);
277
278 /* callingName { */
279 msgb_put_u8(msg, 0xA0);
280 opt_len_ptr = msgb_put(msg, 1);
281 msgb_put_u8(msg, 0xA0);
282 cal_len_ptr = msgb_put(msg, 1);
283
284 /* namePresentationAllowed { */
285 /* add the DCS value */
286 msgb_put_u8(msg, 0x80);
287 msgb_put_u8(msg, 1);
288 msgb_put_u8(msg, 0x0F);
289
290 /* add the lengthInCharacters */
291 msgb_put_u8(msg, 0x81);
292 msgb_put_u8(msg, 1);
293 msgb_put_u8(msg, strlen(text));
294
295 /* add the actual string */
296 msgb_put_u8(msg, 0x82);
297 tmp_len = msgb_put(msg, 1);
298 data = msgb_put(msg, 0);
299 len = gsm_7bit_encode(data, text);
300 tmp_len[0] = len;
301 msgb_put(msg, len);
302
303 /* }; namePresentationAllowed */
304
305 cal_len_ptr[0] = 3 + 3 + 2 + len;
306 opt_len_ptr[0] = cal_len_ptr[0] + 2;
307 /* }; callingName */
308
309 nam_len_ptr[0] = opt_len_ptr[0] + 2;
310 /* ); nameIndicator */
311
312 /* write the lengths... */
Holger Hans Peter Freyther67daa992010-07-27 04:05:29 +0800313 seq_len_ptr[0] = 3 + nam_len_ptr[0] + 2;
Holger Hans Peter Freyther4e1c7f12010-07-25 18:08:53 +0800314
315 return msg;
316}
317
Holger Hans Peter Freyther74294762010-07-27 18:27:46 +0800318struct msgb *gsm0480_create_unstructuredSS_Notify(int alertPattern, const char *text)
Holger Hans Peter Freyther7461c1c2010-07-26 18:34:27 +0800319{
320 struct msgb *msg;
321 uint8_t *seq_len_ptr, *ussd_len_ptr, *data;
322 int len;
323
324 msg = gsm48_msgb_alloc();
325 if (!msg)
326 return NULL;
327
328 /* SEQUENCE { */
329 msgb_put_u8(msg, GSM_0480_SEQUENCE_TAG);
330 seq_len_ptr = msgb_put(msg, 1);
331
332 /* DCS { */
333 msgb_put_u8(msg, ASN1_OCTET_STRING_TAG);
334 msgb_put_u8(msg, 1);
335 msgb_put_u8(msg, 0x0F);
336 /* } DCS */
337
338 /* USSD-String { */
339 msgb_put_u8(msg, ASN1_OCTET_STRING_TAG);
340 ussd_len_ptr = msgb_put(msg, 1);
341 data = msgb_put(msg, 0);
342 len = gsm_7bit_encode(data, text);
343 msgb_put(msg, len);
344 ussd_len_ptr[0] = len;
345 /* USSD-String } */
346
Holger Hans Peter Freyther74294762010-07-27 18:27:46 +0800347 /* alertingPattern { */
348 msgb_put_u8(msg, ASN1_OCTET_STRING_TAG);
349 msgb_put_u8(msg, 1);
350 msgb_put_u8(msg, alertPattern);
351 /* } alertingPattern */
352
353 seq_len_ptr[0] = 3 + 2 + ussd_len_ptr[0] + 3;
Holger Hans Peter Freyther7461c1c2010-07-26 18:34:27 +0800354 /* } SEQUENCE */
355
356 return msg;
357}
358
Harald Welte03115042009-10-16 08:32:58 +0200359/* Send response to a mobile-originated ProcessUnstructuredSS-Request */
Holger Hans Peter Freyther320c5e12010-06-17 17:35:57 +0800360int gsm0480_send_ussd_response(struct gsm_subscriber_connection *conn,
361 const struct msgb *in_msg, const char *response_text,
362 const struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +0200363{
364 struct msgb *msg = gsm48_msgb_alloc();
365 struct gsm48_hdr *gh;
366 u_int8_t *ptr8;
367 int response_len;
368
Harald Welte03115042009-10-16 08:32:58 +0200369 /* First put the payload text into the message */
Holger Hans Peter Freyther3de5a5b2010-07-26 17:56:55 +0800370 ptr8 = msgb_put(msg, 0);
371 response_len = gsm_7bit_encode(ptr8, response_text);
372 msgb_put(msg, response_len);
Harald Welte03115042009-10-16 08:32:58 +0200373
374 /* Then wrap it as an Octet String */
375 msgb_wrap_with_TL(msg, ASN1_OCTET_STRING_TAG);
376
377 /* Pre-pend the DCS octet string */
378 msgb_push_TLV1(msg, ASN1_OCTET_STRING_TAG, 0x0F);
379
380 /* Then wrap these as a Sequence */
381 msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG);
382
383 /* Pre-pend the operation code */
Harald Weltefb957252009-10-16 08:41:51 +0200384 msgb_push_TLV1(msg, GSM0480_OPERATION_CODE,
385 GSM0480_OP_CODE_PROCESS_USS_REQ);
Harald Welte03115042009-10-16 08:32:58 +0200386
387 /* Wrap the operation code and IA5 string as a sequence */
388 msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG);
389
390 /* Pre-pend the invoke ID */
Mike Haben775a1a42009-10-22 09:56:44 +0200391 msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id);
Harald Welte03115042009-10-16 08:32:58 +0200392
393 /* Wrap this up as a Return Result component */
394 msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_RESULT);
395
396 /* Wrap the component in a Facility message */
397 msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY);
398
399 /* And finally pre-pend the L3 header */
400 gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
Harald Weltedd2a34f2009-10-26 20:42:55 +0100401 gh->proto_discr = GSM48_PDISC_NC_SS | req->transaction_id
Mike Haben775a1a42009-10-22 09:56:44 +0200402 | (1<<7); /* TI direction = 1 */
Harald Welte03115042009-10-16 08:32:58 +0200403 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
404
Holger Hans Peter Freyther320c5e12010-06-17 17:35:57 +0800405 return gsm0808_submit_dtap(conn, msg, 0);
Harald Welte03115042009-10-16 08:32:58 +0200406}
407
Holger Hans Peter Freyther93be0792010-07-26 03:41:11 +0800408/* wrap an invoke around it... the other way around
409 *
410 * 1.) Invoke Component tag
411 * 2.) Invoke ID Tag
412 * 3.) Operation
413 * 4.) Data
414 */
415int gsm0480_wrap_invoke(struct msgb *msg, int op, int link_id)
416{
417 /* 3. operation */
418 msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, op);
419
420 /* 2. invoke id tag */
421 msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, link_id);
422
423 /* 1. component tag */
424 msgb_wrap_with_TL(msg, GSM0480_CTYPE_INVOKE);
425
426 return 0;
427}
428
Holger Hans Peter Freytherd26df292010-07-26 19:05:56 +0800429/* wrap the GSM 04.08 Facility IE around it */
430int gsm0480_wrap_facility(struct msgb *msg)
431{
432 msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY);
433
434 return 0;
435}
436
Holger Hans Peter Freyther320c5e12010-06-17 17:35:57 +0800437int gsm0480_send_ussd_reject(struct gsm_subscriber_connection *conn,
438 const struct msgb *in_msg,
439 const struct ussd_request *req)
Harald Welte03115042009-10-16 08:32:58 +0200440{
441 struct msgb *msg = gsm48_msgb_alloc();
442 struct gsm48_hdr *gh;
443
Harald Welte03115042009-10-16 08:32:58 +0200444 /* First insert the problem code */
Harald Weltefb957252009-10-16 08:41:51 +0200445 msgb_push_TLV1(msg, GSM_0480_PROBLEM_CODE_TAG_GENERAL,
446 GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
Harald Welte03115042009-10-16 08:32:58 +0200447
448 /* Before it insert the invoke ID */
Mike Haben775a1a42009-10-22 09:56:44 +0200449 msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id);
Harald Welte03115042009-10-16 08:32:58 +0200450
451 /* Wrap this up as a Reject component */
452 msgb_wrap_with_TL(msg, GSM0480_CTYPE_REJECT);
453
454 /* Wrap the component in a Facility message */
455 msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY);
456
457 /* And finally pre-pend the L3 header */
458 gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
Harald Weltefb957252009-10-16 08:41:51 +0200459 gh->proto_discr = GSM48_PDISC_NC_SS;
Mike Haben775a1a42009-10-22 09:56:44 +0200460 gh->proto_discr |= req->transaction_id | (1<<7); /* TI direction = 1 */
Harald Welte03115042009-10-16 08:32:58 +0200461 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
462
Holger Hans Peter Freyther320c5e12010-06-17 17:35:57 +0800463 return gsm0808_submit_dtap(conn, msg, 0);
Harald Welte03115042009-10-16 08:32:58 +0200464}
Holger Hans Peter Freytherb506d722010-07-26 20:01:07 +0800465
Holger Hans Peter Freyther74294762010-07-27 18:27:46 +0800466int gsm0480_send_ussdNotify(struct gsm_subscriber_connection *conn, int level, const char *text)
Holger Hans Peter Freytherb506d722010-07-26 20:01:07 +0800467{
468 struct gsm48_hdr *gh;
469 struct msgb *msg;
470
Holger Hans Peter Freyther74294762010-07-27 18:27:46 +0800471 msg = gsm0480_create_unstructuredSS_Notify(level, text);
Holger Hans Peter Freytherb506d722010-07-26 20:01:07 +0800472 if (!msg)
473 return -1;
474
475 gsm0480_wrap_invoke(msg, GSM0480_OP_CODE_USS_NOTIFY, 0);
476 gsm0480_wrap_facility(msg);
477
478 /* And finally pre-pend the L3 header */
479 gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
480 gh->proto_discr = GSM48_PDISC_NC_SS;
481 gh->msg_type = GSM0480_MTYPE_REGISTER;
482
483 return gsm0808_submit_dtap(conn, msg, 0);
484}
Holger Hans Peter Freyther90597902010-07-27 03:31:50 +0800485
486int gsm0480_send_releaseComplete(struct gsm_subscriber_connection *conn)
487{
488 struct gsm48_hdr *gh;
489 struct msgb *msg;
490
491 msg = gsm48_msgb_alloc();
492 if (!msg)
493 return -1;
494
495 gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));
496 gh->proto_discr = GSM48_PDISC_NC_SS;
497 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
498
499 return gsm0808_submit_dtap(conn, msg, 0);
500}