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 |
| 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 Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 32 | #include <openbsc/debug.h> |
| 33 | #include <openbsc/gsm_data.h> |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 34 | #include <openbsc/gsm_04_08.h> |
| 35 | #include <openbsc/gsm_04_80.h> |
Holger Hans Peter Freyther | 5bc4d1d | 2010-06-15 13:57:40 +0800 | [diff] [blame] | 36 | #include <openbsc/bsc_api.h> |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 37 | |
Holger Hans Peter Freyther | a5386d1 | 2010-09-30 18:53:47 +0800 | [diff] [blame] | 38 | #include <osmocore/gsm0480.h> |
Holger Hans Peter Freyther | a101b4b | 2010-09-30 18:48:28 +0800 | [diff] [blame] | 39 | #include <osmocore/gsm_utils.h> |
| 40 | #include <osmocore/msgb.h> |
| 41 | #include <osmocore/tlv.h> |
| 42 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 43 | /* Forward declarations */ |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 44 | static int parse_ussd(u_int8_t *ussd, struct ussd_request *req); |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 45 | static int parse_ussd_info_elements(u_int8_t *ussd_ie, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 46 | struct ussd_request *req); |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 47 | static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 48 | struct ussd_request *req); |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 49 | static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 50 | struct ussd_request *req); |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 51 | static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 52 | struct ussd_request *req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 53 | |
| 54 | static inline unsigned char *msgb_wrap_with_TL(struct msgb *msgb, u_int8_t tag) |
| 55 | { |
Holger Hans Peter Freyther | bb2418a | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 56 | uint8_t *data = msgb_push(msgb, 2); |
| 57 | |
| 58 | data[0] = tag; |
Holger Hans Peter Freyther | 0c465ef | 2010-07-27 01:25:59 +0800 | [diff] [blame] | 59 | data[1] = msgb->len - 2; |
Holger Hans Peter Freyther | bb2418a | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 60 | return data; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 61 | } |
| 62 | |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 63 | static inline unsigned char *msgb_push_TLV1(struct msgb *msgb, u_int8_t tag, |
| 64 | u_int8_t value) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 65 | { |
Holger Hans Peter Freyther | bb2418a | 2010-07-26 19:08:59 +0800 | [diff] [blame] | 66 | uint8_t *data = msgb_push(msgb, 3); |
| 67 | |
| 68 | data[0] = tag; |
| 69 | data[1] = 1; |
| 70 | data[2] = value; |
| 71 | return data; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 75 | /* Decode a mobile-originated USSD-request message */ |
Mike Haben | c0c5079 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 76 | int gsm0480_decode_ussd_request(const struct msgb *msg, struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 77 | { |
| 78 | int rc = 0; |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 79 | u_int8_t *parse_ptr = msgb_l3(msg); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 80 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 81 | if ((*parse_ptr & 0x0F) == GSM48_PDISC_NC_SS) { |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 82 | req->transaction_id = *parse_ptr & 0x70; |
| 83 | rc = parse_ussd(parse_ptr+1, req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | if (!rc) |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 87 | DEBUGP(DMM, "Error occurred while parsing received USSD!\n"); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 88 | |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 89 | return rc; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 92 | static int parse_ussd(u_int8_t *ussd, struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 93 | { |
| 94 | int rc = 1; |
| 95 | u_int8_t msg_type = ussd[0] & 0xBF; /* message-type - section 3.4 */ |
| 96 | |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 97 | switch (msg_type) { |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 98 | case GSM0480_MTYPE_RELEASE_COMPLETE: |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 99 | DEBUGP(DMM, "USS Release Complete\n"); |
| 100 | /* could also parse out the optional Cause/Facility data */ |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 101 | req->text[0] = 0xFF; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 102 | break; |
| 103 | case GSM0480_MTYPE_REGISTER: |
| 104 | case GSM0480_MTYPE_FACILITY: |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 105 | rc &= parse_ussd_info_elements(ussd+1, req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 106 | break; |
| 107 | default: |
| 108 | fprintf(stderr, "Unknown GSM 04.80 message-type field 0x%02x\n", |
| 109 | ussd[0]); |
| 110 | rc = 0; |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | return rc; |
| 115 | } |
| 116 | |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 117 | static int parse_ussd_info_elements(u_int8_t *ussd_ie, struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 118 | { |
Holger Hans Peter Freyther | 7394430 | 2010-07-23 19:35:54 +0800 | [diff] [blame] | 119 | int rc = -1; |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 120 | /* Information Element Identifier - table 3.2 & GSM 04.08 section 10.5 */ |
| 121 | u_int8_t iei = ussd_ie[0]; |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 122 | u_int8_t iei_length = ussd_ie[1]; |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 123 | |
| 124 | switch (iei) { |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 125 | case GSM48_IE_CAUSE: |
| 126 | break; |
| 127 | case GSM0480_IE_FACILITY: |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 128 | rc = parse_facility_ie(ussd_ie+2, iei_length, req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 129 | break; |
| 130 | case GSM0480_IE_SS_VERSION: |
| 131 | break; |
| 132 | default: |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 133 | fprintf(stderr, "Unhandled GSM 04.08 or 04.80 IEI 0x%02x\n", |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 134 | iei); |
| 135 | rc = 0; |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | return rc; |
| 140 | } |
| 141 | |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 142 | static int parse_facility_ie(u_int8_t *facility_ie, u_int8_t length, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 143 | struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 144 | { |
| 145 | int rc = 1; |
| 146 | u_int8_t offset = 0; |
| 147 | |
| 148 | do { |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 149 | /* Component Type tag - table 3.7 */ |
| 150 | u_int8_t component_type = facility_ie[offset]; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 151 | u_int8_t component_length = facility_ie[offset+1]; |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 152 | |
| 153 | switch (component_type) { |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 154 | case GSM0480_CTYPE_INVOKE: |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 155 | rc &= parse_ss_invoke(facility_ie+2, |
| 156 | component_length, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 157 | req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 158 | break; |
| 159 | case GSM0480_CTYPE_RETURN_RESULT: |
| 160 | break; |
| 161 | case GSM0480_CTYPE_RETURN_ERROR: |
| 162 | break; |
| 163 | case GSM0480_CTYPE_REJECT: |
| 164 | break; |
| 165 | default: |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 166 | fprintf(stderr, "Unknown GSM 04.80 Facility " |
| 167 | "Component Type 0x%02x\n", component_type); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 168 | rc = 0; |
| 169 | break; |
| 170 | } |
| 171 | offset += (component_length+2); |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 172 | } while (offset < length); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 173 | |
| 174 | return rc; |
| 175 | } |
| 176 | |
| 177 | /* Parse an Invoke component - see table 3.3 */ |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 178 | static int parse_ss_invoke(u_int8_t *invoke_data, u_int8_t length, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 179 | struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 180 | { |
| 181 | int rc = 1; |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 182 | u_int8_t offset; |
| 183 | |
| 184 | /* mandatory part */ |
| 185 | if (invoke_data[0] != GSM0480_COMPIDTAG_INVOKE_ID) { |
| 186 | fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag " |
| 187 | "0x%02x (expecting Invoke ID tag)\n", invoke_data[0]); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 188 | } |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 189 | |
| 190 | offset = invoke_data[1] + 2; |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 191 | req->invoke_id = invoke_data[2]; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 192 | |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 193 | /* optional part */ |
| 194 | if (invoke_data[offset] == GSM0480_COMPIDTAG_LINKED_ID) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 195 | offset += invoke_data[offset+1] + 2; /* skip over it */ |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 196 | |
| 197 | /* mandatory part */ |
| 198 | if (invoke_data[offset] == GSM0480_OPERATION_CODE) { |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 199 | u_int8_t operation_code = invoke_data[offset+2]; |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 200 | switch (operation_code) { |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 201 | case GSM0480_OP_CODE_PROCESS_USS_REQ: |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 202 | rc = parse_process_uss_req(invoke_data + offset + 3, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 203 | length - offset - 3, |
| 204 | req); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 205 | break; |
| 206 | default: |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 207 | fprintf(stderr, "GSM 04.80 operation code 0x%02x " |
| 208 | "is not yet handled\n", operation_code); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 209 | rc = 0; |
| 210 | break; |
| 211 | } |
| 212 | } else { |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 213 | fprintf(stderr, "Unexpected GSM 04.80 Component-ID tag 0x%02x " |
| 214 | "(expecting Operation Code tag)\n", |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 215 | invoke_data[0]); |
| 216 | rc = 0; |
| 217 | } |
| 218 | |
| 219 | return rc; |
| 220 | } |
| 221 | |
| 222 | /* Parse the parameters of a Process UnstructuredSS Request */ |
Harald Welte | 36ec2be | 2009-10-26 20:42:07 +0100 | [diff] [blame] | 223 | static int parse_process_uss_req(u_int8_t *uss_req_data, u_int8_t length, |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 224 | struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 225 | { |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 226 | int rc = 0; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 227 | int num_chars; |
| 228 | u_int8_t dcs; |
| 229 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 230 | if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) { |
| 231 | if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) { |
| 232 | dcs = uss_req_data[4]; |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 233 | if ((dcs == 0x0F) && |
| 234 | (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) { |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 235 | num_chars = (uss_req_data[6] * 8) / 7; |
Mike Haben | c0c5079 | 2009-10-26 20:36:34 +0100 | [diff] [blame] | 236 | /* Prevent a mobile-originated buffer-overrun! */ |
| 237 | if (num_chars > MAX_LEN_USSD_STRING) |
| 238 | num_chars = MAX_LEN_USSD_STRING; |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 239 | gsm_7bit_decode(req->text, |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 240 | &(uss_req_data[7]), num_chars); |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 241 | /* append null-terminator */ |
Holger Hans Peter Freyther | 7113514 | 2010-03-29 08:47:44 +0200 | [diff] [blame] | 242 | req->text[num_chars+1] = 0; |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 243 | rc = 1; |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 244 | } |
| 245 | } |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 246 | } |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 247 | return rc; |
| 248 | } |
| 249 | |
| 250 | /* Send response to a mobile-originated ProcessUnstructuredSS-Request */ |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 251 | int gsm0480_send_ussd_response(struct gsm_subscriber_connection *conn, |
| 252 | const struct msgb *in_msg, const char *response_text, |
| 253 | const struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 254 | { |
| 255 | struct msgb *msg = gsm48_msgb_alloc(); |
| 256 | struct gsm48_hdr *gh; |
| 257 | u_int8_t *ptr8; |
| 258 | int response_len; |
| 259 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 260 | /* First put the payload text into the message */ |
Holger Hans Peter Freyther | 3de5a5b | 2010-07-26 17:56:55 +0800 | [diff] [blame] | 261 | ptr8 = msgb_put(msg, 0); |
| 262 | response_len = gsm_7bit_encode(ptr8, response_text); |
| 263 | msgb_put(msg, response_len); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 264 | |
| 265 | /* Then wrap it as an Octet String */ |
| 266 | msgb_wrap_with_TL(msg, ASN1_OCTET_STRING_TAG); |
| 267 | |
| 268 | /* Pre-pend the DCS octet string */ |
| 269 | msgb_push_TLV1(msg, ASN1_OCTET_STRING_TAG, 0x0F); |
| 270 | |
| 271 | /* Then wrap these as a Sequence */ |
| 272 | msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); |
| 273 | |
| 274 | /* Pre-pend the operation code */ |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 275 | msgb_push_TLV1(msg, GSM0480_OPERATION_CODE, |
| 276 | GSM0480_OP_CODE_PROCESS_USS_REQ); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 277 | |
| 278 | /* Wrap the operation code and IA5 string as a sequence */ |
| 279 | msgb_wrap_with_TL(msg, GSM_0480_SEQUENCE_TAG); |
| 280 | |
| 281 | /* Pre-pend the invoke ID */ |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 282 | msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 283 | |
| 284 | /* Wrap this up as a Return Result component */ |
| 285 | msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_RESULT); |
| 286 | |
| 287 | /* Wrap the component in a Facility message */ |
| 288 | msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY); |
| 289 | |
| 290 | /* And finally pre-pend the L3 header */ |
| 291 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
Harald Welte | dd2a34f | 2009-10-26 20:42:55 +0100 | [diff] [blame] | 292 | gh->proto_discr = GSM48_PDISC_NC_SS | req->transaction_id |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 293 | | (1<<7); /* TI direction = 1 */ |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 294 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 295 | |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 296 | return gsm0808_submit_dtap(conn, msg, 0); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 299 | int gsm0480_send_ussd_reject(struct gsm_subscriber_connection *conn, |
| 300 | const struct msgb *in_msg, |
| 301 | const struct ussd_request *req) |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 302 | { |
| 303 | struct msgb *msg = gsm48_msgb_alloc(); |
| 304 | struct gsm48_hdr *gh; |
| 305 | |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 306 | /* First insert the problem code */ |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 307 | msgb_push_TLV1(msg, GSM_0480_PROBLEM_CODE_TAG_GENERAL, |
| 308 | GSM_0480_GEN_PROB_CODE_UNRECOGNISED); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 309 | |
| 310 | /* Before it insert the invoke ID */ |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 311 | msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 312 | |
| 313 | /* Wrap this up as a Reject component */ |
| 314 | msgb_wrap_with_TL(msg, GSM0480_CTYPE_REJECT); |
| 315 | |
| 316 | /* Wrap the component in a Facility message */ |
| 317 | msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY); |
| 318 | |
| 319 | /* And finally pre-pend the L3 header */ |
| 320 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
Harald Welte | fb95725 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 321 | gh->proto_discr = GSM48_PDISC_NC_SS; |
Mike Haben | 775a1a4 | 2009-10-22 09:56:44 +0200 | [diff] [blame] | 322 | gh->proto_discr |= req->transaction_id | (1<<7); /* TI direction = 1 */ |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 323 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 324 | |
Holger Hans Peter Freyther | 320c5e1 | 2010-06-17 17:35:57 +0800 | [diff] [blame] | 325 | return gsm0808_submit_dtap(conn, msg, 0); |
Harald Welte | 0311504 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 326 | } |
Holger Hans Peter Freyther | b506d72 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 327 | |
Holger Hans Peter Freyther | 7429476 | 2010-07-27 18:27:46 +0800 | [diff] [blame] | 328 | 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] | 329 | { |
| 330 | struct gsm48_hdr *gh; |
| 331 | struct msgb *msg; |
| 332 | |
Holger Hans Peter Freyther | 7429476 | 2010-07-27 18:27:46 +0800 | [diff] [blame] | 333 | msg = gsm0480_create_unstructuredSS_Notify(level, text); |
Holger Hans Peter Freyther | b506d72 | 2010-07-26 20:01:07 +0800 | [diff] [blame] | 334 | if (!msg) |
| 335 | return -1; |
| 336 | |
| 337 | gsm0480_wrap_invoke(msg, GSM0480_OP_CODE_USS_NOTIFY, 0); |
| 338 | gsm0480_wrap_facility(msg); |
| 339 | |
| 340 | /* And finally pre-pend the L3 header */ |
| 341 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
| 342 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 343 | gh->msg_type = GSM0480_MTYPE_REGISTER; |
| 344 | |
| 345 | return gsm0808_submit_dtap(conn, msg, 0); |
| 346 | } |
Holger Hans Peter Freyther | 9059790 | 2010-07-27 03:31:50 +0800 | [diff] [blame] | 347 | |
| 348 | int gsm0480_send_releaseComplete(struct gsm_subscriber_connection *conn) |
| 349 | { |
| 350 | struct gsm48_hdr *gh; |
| 351 | struct msgb *msg; |
| 352 | |
| 353 | msg = gsm48_msgb_alloc(); |
| 354 | if (!msg) |
| 355 | return -1; |
| 356 | |
| 357 | gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh)); |
| 358 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 359 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 360 | |
| 361 | return gsm0808_submit_dtap(conn, msg, 0); |
| 362 | } |