Harald Welte | dd2a34f | 2009-10-26 20:42:55 +0100 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 2 | * 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 Freyther | 4e1c7f1 | 2010-07-25 18:08:53 +0800 | [diff] [blame] | 5 | * (C) 2008, 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 6 | * (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 |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 11 | * it under the terms of the GNU Affero General Public License as published by |
| 12 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 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 |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * GNU Affero General Public License for more details. |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 19 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 20 | * You should have received a copy of the GNU Affero General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <errno.h> |
| 30 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 31 | #include <openbsc/debug.h> |
| 32 | #include <openbsc/gsm_data.h> |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 33 | #include <openbsc/gsm_04_08.h> |
| 34 | #include <openbsc/gsm_04_80.h> |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 35 | #include <openbsc/bsc_api.h> |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | a5386d1 | 2010-09-30 18:53:47 +0800 | [diff] [blame] | 37 | #include <osmocore/gsm0480.h> |
Holger Hans Peter Freyther | a101b4b | 2010-09-30 18:48:28 +0800 | [diff] [blame] | 38 | #include <osmocore/gsm_utils.h> |
| 39 | #include <osmocore/msgb.h> |
| 40 | #include <osmocore/tlv.h> |
| 41 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 42 | static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, u_int8_t tag) |
| 43 | { |
Holger Hans Peter Freyther | bb2418a | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 44 | uint8_t *data = msgb_push(msgb, 2); |
| 45 | |
| 46 | data[0] = tag; |
Holger Hans Peter Freyther | 0c465ef | 2010-07-27 01:25:59 +0800 | [diff] [blame] | 47 | data[1] = msgb->len - 2; |
Holger Hans Peter Freyther | bb2418a | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 48 | return data; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 51 | static inline unsigned char *msgb_push_TLV1(struct msgb *msgb, u_int8_t tag, |
| 52 | u_int8_t value) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 53 | { |
Holger Hans Peter Freyther | bb2418a | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 54 | uint8_t *data = msgb_push(msgb, 3); |
| 55 | |
| 56 | data[0] = tag; |
| 57 | data[1] = 1; |
| 58 | data[2] = value; |
| 59 | return data; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 63 | /* Send response to a mobile-originated ProcessUnstructuredSS-Request */ |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 64 | int gsm0480_send_ussd_response(struct gsm_subscriber_connection *conn, |
| 65 | const struct msgb *in_msg, const char *response_text, |
| 66 | const struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 67 | { |
| 68 | struct msgb *msg = gsm48_msgb_alloc(); |
| 69 | struct gsm48_hdr *gh; |
| 70 | u_int8_t *ptr8; |
| 71 | int response_len; |
| 72 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 73 | /* First put the payload text into the message */ |
Holger Hans Peter Freyther | 3de5a5b | 2010-07-26 17:56:55 +0800 | [diff] [blame] | 74 | ptr8 = msgb_put(msg, 0); |
| 75 | response_len = gsm_7bit_encode(ptr8, response_text); |
| 76 | msgb_put(msg, response_len); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 77 | |
| 78 | /* Then wrap it as an Octet String */ |
| 79 | msgb_wrap_with_TL(msg, ASN1_OCTET_STRING_TAG); |
| 80 | |
| 81 | /* Pre-pend the DCS octet string */ |
| 82 | msgb_push_TLV1(msg, ASN1_OCTET_STRING_TAG, 0x0F); |
| 83 | |
| 84 | /* Then wrap these as a Sequence */ |
| 85 | msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); |
| 86 | |
| 87 | /* Pre-pend the operation code */ |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 88 | msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, |
| 89 | GSM0480_OP_CODE_PROCESS_USS_REQ); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 90 | |
| 91 | /* Wrap the operation code and IA5 string as a sequence */ |
| 92 | msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); |
| 93 | |
| 94 | /* Pre-pend the invoke ID */ |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 95 | msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 96 | |
| 97 | /* Wrap this up as a Return Result component */ |
| 98 | msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_RESULT); |
| 99 | |
| 100 | /* Wrap the component in a Facility message */ |
| 101 | msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY); |
| 102 | |
| 103 | /* And finally pre-pend the L3 header */ |
| 104 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
Harald Welte | dd2a34f | 2009-10-26 20:42:55 +0100 | [diff] [blame] | 105 | gh->proto_discr = GSM48_PDISC_NC_SS | req->transaction_id |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 106 | | (1<<7); /* TI direction = 1 */ |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 107 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 108 | |
Holger Hans Peter Freyther | 6bfcad8 | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 109 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 112 | int gsm0480_send_ussd_reject(struct gsm_subscriber_connection *conn, |
| 113 | const struct msgb *in_msg, |
| 114 | const struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 115 | { |
| 116 | struct msgb *msg = gsm48_msgb_alloc(); |
| 117 | struct gsm48_hdr *gh; |
| 118 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 119 | /* First insert the problem code */ |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 120 | msgb_push_TLV1(msg, GSM_0480_PROBLEM_CODE_TAG_GENERAL, |
| 121 | GSM_0480_GEN_PROB_CODE_UNRECOGNISED); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 122 | |
| 123 | /* Before it insert the invoke ID */ |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 124 | msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 125 | |
| 126 | /* Wrap this up as a Reject component */ |
| 127 | msgb_wrap_with_TL(msg, GSM0480_CTYPE_REJECT); |
| 128 | |
| 129 | /* Wrap the component in a Facility message */ |
| 130 | msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY); |
| 131 | |
| 132 | /* And finally pre-pend the L3 header */ |
| 133 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 134 | gh->proto_discr = GSM48_PDISC_NC_SS; |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 135 | gh->proto_discr |= req->transaction_id | (1<<7); /* TI direction = 1 */ |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 136 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 137 | |
Holger Hans Peter Freyther | 6bfcad8 | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 138 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 139 | } |
Holger Hans Peter Freyther | b506d72 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 140 | |
Holger Hans Peter Freyther | 7429476 | 2010-07-27 18:27:46 +0800 | [diff] [blame] | 141 | int gsm0480_send_ussdNotify(struct gsm_subscriber_connection *conn, int level, const char *text) |
Holger Hans Peter Freyther | b506d72 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 142 | { |
| 143 | struct gsm48_hdr *gh; |
| 144 | struct msgb *msg; |
| 145 | |
Holger Hans Peter Freyther | 7429476 | 2010-07-27 18:27:46 +0800 | [diff] [blame] | 146 | msg = gsm0480_create_unstructuredSS_Notify(level, text); |
Holger Hans Peter Freyther | b506d72 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 147 | if (!msg) |
| 148 | return -1; |
| 149 | |
| 150 | gsm0480_wrap_invoke(msg, GSM0480_OP_CODE_USS_NOTIFY, 0); |
| 151 | gsm0480_wrap_facility(msg); |
| 152 | |
| 153 | /* And finally pre-pend the L3 header */ |
| 154 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
| 155 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 156 | gh->msg_type = GSM0480_MTYPE_REGISTER; |
| 157 | |
Holger Hans Peter Freyther | 6bfcad8 | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 158 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
Holger Hans Peter Freyther | b506d72 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 159 | } |
Holger Hans Peter Freyther | 9059790 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 160 | |
| 161 | int gsm0480_send_releaseComplete(struct gsm_subscriber_connection *conn) |
| 162 | { |
| 163 | struct gsm48_hdr *gh; |
| 164 | struct msgb *msg; |
| 165 | |
| 166 | msg = gsm48_msgb_alloc(); |
| 167 | if (!msg) |
| 168 | return -1; |
| 169 | |
| 170 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
| 171 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 172 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 173 | |
Holger Hans Peter Freyther | 6bfcad8 | 2010-11-10 10:16:02 +0100 | [diff] [blame] | 174 | return gsm0808_submit_dtap(conn, msg, 0, 0); |
Holger Hans Peter Freyther | 9059790 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 175 | } |